Adds first prototype code to create navigation categories, needs majour cleanup and optimisations
This commit is contained in:
parent
2fbec8869d
commit
82e1d9fc0c
23 changed files with 237 additions and 324 deletions
|
@ -56,28 +56,79 @@ int BlogPageBuilder::calculateIdentifierLocation(std::string id, std::string tex
|
|||
|
||||
void BlogPageBuilder::collectPages()
|
||||
{
|
||||
auto directoryIterator = std::filesystem::directory_iterator(inFolder);
|
||||
auto directoryIterator = std::filesystem::recursive_directory_iterator(inFolder);
|
||||
for(auto file : directoryIterator)
|
||||
{
|
||||
if (file.is_directory())
|
||||
continue;
|
||||
pages.push_back(new Page(file.path(), outFolder));
|
||||
}
|
||||
}
|
||||
|
||||
std::string BlogPageBuilder::generateNavSection()
|
||||
std::string BlogPageBuilder::generateCategories(std::string rootFolderUrl)
|
||||
{
|
||||
std::stringstream buffer;
|
||||
buffer << "\n<h1>Navigation</h1>\n\n";
|
||||
auto directoryIterator = std::filesystem::directory_iterator(rootFolderUrl);
|
||||
for (auto folder : directoryIterator)
|
||||
{
|
||||
if (folder.is_directory())
|
||||
{
|
||||
std::string path = folder.path();
|
||||
std::string folderName = path.substr(path.find_last_of("/")+1, path.length()-path.find_last_of("/"));
|
||||
|
||||
buffer << "\n<h2>" << folderName << "</h2>\n";
|
||||
buffer << generateCategories(folder.path());
|
||||
buffer << "\n";
|
||||
|
||||
}
|
||||
}
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
std::string BlogPageBuilder::findDeepestCategory(std::string url)
|
||||
{
|
||||
int categoryEnd = url.rfind("/");
|
||||
int categoryStart = url.rfind("/", categoryEnd-1);
|
||||
if (categoryStart == -1)
|
||||
categoryStart = 0;
|
||||
return url.substr(categoryStart, categoryEnd);
|
||||
}
|
||||
|
||||
std::string BlogPageBuilder::insertPagesIntoCategories(std::string categories)
|
||||
{
|
||||
for (Page* page : pages)
|
||||
{
|
||||
if (page->getPageFlags().hidden &&
|
||||
isOptionEnabled(OptionFlags::HIDE_PRIVATE))
|
||||
continue;
|
||||
buffer
|
||||
<< "<li><a href=" << page->getRelativeOutUrl() << ">"
|
||||
<< page->getPageTitle()
|
||||
<< "</a></li>\n";
|
||||
|
||||
std::string item;
|
||||
item.append("<li><a href=" + page->getRelativeOutUrl() + ">"
|
||||
+ page->getPageTitle()
|
||||
+ "</a></li>\n");
|
||||
|
||||
std::string categoryOpening = "\n";
|
||||
int categoryStart = categories.find(findDeepestCategory(page->getRelativeInUrl()));
|
||||
int insertLocation = 0;
|
||||
if (categoryStart != -1)
|
||||
insertLocation = categories.find(categoryOpening, categoryStart) + categoryOpening.length();
|
||||
else
|
||||
insertLocation = navHeader.length();
|
||||
|
||||
|
||||
categories.insert(insertLocation, item);
|
||||
}
|
||||
return buffer.str();
|
||||
|
||||
return categories;
|
||||
}
|
||||
|
||||
std::string BlogPageBuilder::generateNavSection()
|
||||
{
|
||||
std::string buffer;
|
||||
buffer.append(navHeader);
|
||||
buffer.append(generateCategories(SOURCE_FILE_FOLDER));
|
||||
buffer = insertPagesIntoCategories(buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::string BlogPageBuilder::readFile(std::string fileUrl)
|
||||
|
|
|
@ -42,7 +42,14 @@ private:
|
|||
int calculateIdentifierLocation(std::string id, std::string text);
|
||||
void collectPages();
|
||||
|
||||
// TODO separate these into a separate object
|
||||
std::string navHeader = "\n<h1>Navigation</h1>\n\n";
|
||||
|
||||
std::string generateNavSection();
|
||||
std::string generateCategories(std::string rootFolderUrl);
|
||||
std::string insertPagesIntoCategories(std::string categories);
|
||||
std::string findDeepestCategory(std::string url);
|
||||
|
||||
void createPage(Page* page);
|
||||
bool isOptionEnabled(int flag);
|
||||
|
||||
|
|
|
@ -118,10 +118,6 @@ void Page::writePageToFile()
|
|||
printf("failed to write file to %s \n", outFileUrl.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
FileFlags FlagReader::readFlags(std::string flagString)
|
||||
{
|
||||
FileFlags flags;
|
||||
|
|
20
Src/Page.h
20
Src/Page.h
|
@ -62,23 +62,3 @@ public:
|
|||
void writePageToFile();
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Class to represent the structure of the nav menu, the categories of the pages
|
||||
*/
|
||||
// A node can either be a file or a folder, value for each possibility.
|
||||
struct PageTreeNode
|
||||
{
|
||||
std::vector<PageTreeNode> branches;
|
||||
Page* pageValue;
|
||||
std::string folderValue;
|
||||
};
|
||||
|
||||
class PageTree
|
||||
{
|
||||
private:
|
||||
PageTreeNode* rootNode;
|
||||
public:
|
||||
PageTreeNode* getNodeLinear(int x);
|
||||
std::vector<PageTreeNode> getTreeAsList();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue