Moves navbar generation to its own class and adds ordering of categories
This commit is contained in:
parent
e514df19fb
commit
5765d04fe6
12 changed files with 88 additions and 41 deletions
|
@ -16,6 +16,10 @@
|
|||
<li><a href=/TestFullArticle.html>Example Post</a></li>
|
||||
<li><a href=/index.html>Welcome!</a></li>
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
|
||||
|
||||
<h2>Older Work</h2>
|
||||
<li><a href=/MindMap.html>Mind Map Maker</a></li>
|
||||
<li><a href=/Aardvark.html>AardvarkXR</a></li>
|
||||
|
@ -23,8 +27,7 @@
|
|||
<li><a href=/CatTowerDefence.html>Tower defence game</a></li>
|
||||
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
<h2>Thoughts And Essays</h2>
|
||||
|
||||
|
||||
<h2>University</h2>
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
<li><a href=/TestFullArticle.html>Example Post</a></li>
|
||||
<li><a href=/index.html>Welcome!</a></li>
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
|
||||
|
||||
<h2>Older Work</h2>
|
||||
<li><a href=/MindMap.html>Mind Map Maker</a></li>
|
||||
<li><a href=/Aardvark.html>AardvarkXR</a></li>
|
||||
|
@ -23,8 +27,7 @@
|
|||
<li><a href=/CatTowerDefence.html>Tower defence game</a></li>
|
||||
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
<h2>Thoughts And Essays</h2>
|
||||
|
||||
|
||||
<h2>University</h2>
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
<li><a href=/TestFullArticle.html>Example Post</a></li>
|
||||
<li><a href=/index.html>Welcome!</a></li>
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
|
||||
|
||||
<h2>Older Work</h2>
|
||||
<li><a href=/MindMap.html>Mind Map Maker</a></li>
|
||||
<li><a href=/Aardvark.html>AardvarkXR</a></li>
|
||||
|
@ -23,8 +27,7 @@
|
|||
<li><a href=/CatTowerDefence.html>Tower defence game</a></li>
|
||||
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
<h2>Thoughts And Essays</h2>
|
||||
|
||||
|
||||
<h2>University</h2>
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
<li><a href=/TestFullArticle.html>Example Post</a></li>
|
||||
<li><a href=/index.html>Welcome!</a></li>
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
|
||||
|
||||
<h2>Older Work</h2>
|
||||
<li><a href=/MindMap.html>Mind Map Maker</a></li>
|
||||
<li><a href=/Aardvark.html>AardvarkXR</a></li>
|
||||
|
@ -23,8 +27,7 @@
|
|||
<li><a href=/CatTowerDefence.html>Tower defence game</a></li>
|
||||
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
<h2>Thoughts And Essays</h2>
|
||||
|
||||
|
||||
<h2>University</h2>
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
<li><a href=/TestFullArticle.html>Example Post</a></li>
|
||||
<li><a href=/index.html>Welcome!</a></li>
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
|
||||
|
||||
<h2>Older Work</h2>
|
||||
<li><a href=/MindMap.html>Mind Map Maker</a></li>
|
||||
<li><a href=/Aardvark.html>AardvarkXR</a></li>
|
||||
|
@ -23,8 +27,7 @@
|
|||
<li><a href=/CatTowerDefence.html>Tower defence game</a></li>
|
||||
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
<h2>Thoughts And Essays</h2>
|
||||
|
||||
|
||||
<h2>University</h2>
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
<li><a href=/TestFullArticle.html>Example Post</a></li>
|
||||
<li><a href=/index.html>Welcome!</a></li>
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
|
||||
|
||||
<h2>Older Work</h2>
|
||||
<li><a href=/MindMap.html>Mind Map Maker</a></li>
|
||||
<li><a href=/Aardvark.html>AardvarkXR</a></li>
|
||||
|
@ -23,8 +27,7 @@
|
|||
<li><a href=/CatTowerDefence.html>Tower defence game</a></li>
|
||||
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
<h2>Thoughts And Essays</h2>
|
||||
|
||||
|
||||
<h2>University</h2>
|
||||
|
|
|
@ -17,11 +17,12 @@ nav{
|
|||
}
|
||||
|
||||
nav h1{
|
||||
font-size: 1.2rem;
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
|
||||
nav h2{
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
article{
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
<li><a href=/TestFullArticle.html>Example Post</a></li>
|
||||
<li><a href=/index.html>Welcome!</a></li>
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
|
||||
|
||||
<h2>Older Work</h2>
|
||||
<li><a href=/MindMap.html>Mind Map Maker</a></li>
|
||||
<li><a href=/Aardvark.html>AardvarkXR</a></li>
|
||||
|
@ -23,8 +27,7 @@
|
|||
<li><a href=/CatTowerDefence.html>Tower defence game</a></li>
|
||||
|
||||
|
||||
<h2>Newer Work</h2>
|
||||
<li><a href=/ThisSite.html>This Site</a></li>
|
||||
<h2>Thoughts And Essays</h2>
|
||||
|
||||
|
||||
<h2>University</h2>
|
||||
|
|
|
@ -17,11 +17,12 @@ nav{
|
|||
}
|
||||
|
||||
nav h1{
|
||||
font-size: 1rem;
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
|
||||
nav h2{
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
article{
|
||||
|
|
|
@ -14,7 +14,10 @@ BlogPageBuilder::BlogPageBuilder(std::string templateFileUrl, std::string inFold
|
|||
parser = new BlogParser();
|
||||
|
||||
collectPages();
|
||||
navSection = generateNavSection();
|
||||
|
||||
NavBarGenerator* navGen = new NavBarGenerator();
|
||||
navSection = navGen->generateNavSection(pages, options);
|
||||
delete navGen;
|
||||
}
|
||||
|
||||
BlogPageBuilder::~BlogPageBuilder()
|
||||
|
@ -65,9 +68,12 @@ void BlogPageBuilder::collectPages()
|
|||
}
|
||||
}
|
||||
|
||||
std::string BlogPageBuilder::generateCategories(std::string rootFolderUrl)
|
||||
std::string NavBarGenerator::generateCategories(std::string rootFolderUrl)
|
||||
{
|
||||
std::stringstream buffer;
|
||||
|
||||
std::set<std::string> categories;
|
||||
|
||||
auto directoryIterator = std::filesystem::directory_iterator(rootFolderUrl);
|
||||
for (auto folder : directoryIterator)
|
||||
{
|
||||
|
@ -76,16 +82,20 @@ std::string BlogPageBuilder::generateCategories(std::string rootFolderUrl)
|
|||
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";
|
||||
|
||||
categories.insert(folderName);
|
||||
}
|
||||
}
|
||||
|
||||
for (std::string category : categories)
|
||||
{
|
||||
buffer << "\n<h2>" << category << "</h2>\n";
|
||||
buffer << generateCategories(rootFolderUrl + "/" + category);
|
||||
buffer << "\n";
|
||||
}
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
std::string BlogPageBuilder::findDeepestCategory(std::string url)
|
||||
std::string NavBarGenerator::findDeepestCategory(std::string url)
|
||||
{
|
||||
int categoryEnd = url.rfind("/");
|
||||
int categoryStart = url.rfind("/", categoryEnd-1);
|
||||
|
@ -94,7 +104,7 @@ std::string BlogPageBuilder::findDeepestCategory(std::string url)
|
|||
return url.substr(categoryStart, categoryEnd);
|
||||
}
|
||||
|
||||
std::string BlogPageBuilder::insertPagesIntoCategories(std::string categories)
|
||||
std::string NavBarGenerator::insertPagesIntoCategories(std::string categories, std::vector<Page*> pages)
|
||||
{
|
||||
for (Page* page : pages)
|
||||
{
|
||||
|
@ -122,12 +132,13 @@ std::string BlogPageBuilder::insertPagesIntoCategories(std::string categories)
|
|||
return categories;
|
||||
}
|
||||
|
||||
std::string BlogPageBuilder::generateNavSection()
|
||||
std::string NavBarGenerator::generateNavSection(std::vector<Page*> pages, int options)
|
||||
{
|
||||
this->options = options;
|
||||
std::string buffer;
|
||||
buffer.append(navHeader);
|
||||
buffer.append(generateCategories(SOURCE_FILE_FOLDER));
|
||||
buffer = insertPagesIntoCategories(buffer);
|
||||
buffer = insertPagesIntoCategories(buffer, pages);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -144,3 +155,8 @@ bool BlogPageBuilder::isOptionEnabled(int flag)
|
|||
{
|
||||
return (options & flag) == flag;
|
||||
}
|
||||
|
||||
bool NavBarGenerator::isOptionEnabled(int flag)
|
||||
{
|
||||
return (options & flag) == flag;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
#include <set>
|
||||
|
||||
#include "BlogParser.h"
|
||||
#include "Page.h"
|
||||
|
@ -14,15 +15,30 @@
|
|||
* along with an optional articleIdentifier. The template is searched for this
|
||||
* and the blog is placed after it.
|
||||
*/
|
||||
|
||||
class BlogPageBuilder
|
||||
{
|
||||
public:
|
||||
enum OptionFlags
|
||||
enum OptionFlags
|
||||
{
|
||||
NONE = 0X0,
|
||||
HIDE_PRIVATE = 0x1
|
||||
};
|
||||
|
||||
class NavBarGenerator
|
||||
{
|
||||
private:
|
||||
std::string navHeader = "\n<h1>Navigation</h1>\n\n";
|
||||
int options;
|
||||
|
||||
std::string generateCategories(std::string rootFolderUrl);
|
||||
std::string insertPagesIntoCategories(std::string categories, std::vector<Page*> pages);
|
||||
std::string findDeepestCategory(std::string url);
|
||||
|
||||
bool isOptionEnabled(int flag);
|
||||
|
||||
public:
|
||||
std::string generateNavSection(std::vector<Page*> pages, int options);
|
||||
};
|
||||
|
||||
class BlogPageBuilder
|
||||
{
|
||||
private:
|
||||
int options;
|
||||
|
||||
|
@ -42,14 +58,6 @@ 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);
|
||||
|
||||
|
|
|
@ -65,9 +65,9 @@ int main(int argc, char* argv[])
|
|||
std::string output = getArgValue(argc, argv, "-out=");
|
||||
if (output == "")
|
||||
output = OUTPUT_FILE_FOLDER;
|
||||
int flags = BlogPageBuilder::OptionFlags::NONE;
|
||||
int flags = OptionFlags::NONE;
|
||||
if (doesArgExist(argc, argv, "-hide"))
|
||||
flags |= BlogPageBuilder::OptionFlags::HIDE_PRIVATE;
|
||||
flags |= OptionFlags::HIDE_PRIVATE;
|
||||
|
||||
// generated pages
|
||||
BlogPageBuilder* builder = new BlogPageBuilder(RESOURCE_FOLDER "/Templates/BlogPageTemplate.html", source, output, flags);
|
||||
|
|
Loading…
Add table
Reference in a new issue