Adds prototype for mapping out pages for navigation sections

This commit is contained in:
Rosia E Evans 2023-10-09 13:53:09 +01:00
parent dc03e239d5
commit 2fbec8869d
14 changed files with 69 additions and 9 deletions

View file

@ -73,7 +73,7 @@ std::string BlogPageBuilder::generateNavSection()
isOptionEnabled(OptionFlags::HIDE_PRIVATE))
continue;
buffer
<< "<li><a href=" << page->getRelativeUrl() << ">"
<< "<li><a href=" << page->getRelativeOutUrl() << ">"
<< page->getPageTitle()
<< "</a></li>\n";
}

View file

@ -32,7 +32,7 @@ Page::Page(std::string sourceFileUrl, std::string outFolderUrl)
calculatePageFlags();
calculatePageTitle();
this->outFileUrl = outFolderUrl + getRelativeUrl();
this->outFileUrl = outFolderUrl + getRelativeOutUrl();
}
std::string Page::getSourceFileContents()
@ -40,12 +40,13 @@ std::string Page::getSourceFileContents()
return sourceFileContents;
}
std::string Page::getOutFileUrl()
std::string Page::getOutUrl()
{
return outFileUrl;
}
std::string Page::getRelativeUrl()
// includes first /
std::string Page::getRelativeOutUrl()
{
int start = sourceFileUrl.find_last_of("/");
std::string relativeUrl = std::string(sourceFileUrl).substr(start, sourceFileUrl.length()-start);
@ -53,6 +54,20 @@ std::string Page::getRelativeUrl()
return relativeUrl;
}
std::string Page::getInUrl()
{
return sourceFileUrl;
}
// includes first /
std::string Page::getRelativeInUrl()
{
int start = strlen(SOURCE_FILE_FOLDER)+1;
std::string relativeUrl = std::string(sourceFileUrl).substr(start, sourceFileUrl.length()-start);
relativeUrl.replace(relativeUrl.length()-3, 3, ".html");
return relativeUrl;
}
FileFlags Page::getPageFlags()
{
return flags;

View file

@ -3,6 +3,10 @@
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include "MacroDefinitions.h"
struct FileFlags
@ -43,8 +47,13 @@ public:
Page(std::string sourceFileUrl, std::string outFolderUrl);
std::string getSourceFileContents();
std::string getOutFileUrl();
std::string getRelativeUrl();
std::string getInUrl();
std::string getRelativeInUrl();
std::string getOutUrl();
std::string getRelativeOutUrl();
std::string getPageTitle();
FileFlags getPageFlags();
@ -53,3 +62,23 @@ 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();
};