Adds first prototype code to create navigation categories, needs majour cleanup and optimisations

This commit is contained in:
Rosia E Evans 2023-10-11 00:19:40 +01:00
parent 2fbec8869d
commit 82e1d9fc0c
23 changed files with 237 additions and 324 deletions

View file

@ -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)