Changes to file naming system, names are no longer generated, they are instead take from source files name
Option to hide private posts is no an argument in program
This commit is contained in:
parent
63c9374ea9
commit
63fc2fa47f
18 changed files with 48 additions and 407 deletions
|
@ -2,8 +2,9 @@
|
|||
|
||||
|
||||
BlogPageBuilder::BlogPageBuilder(std::string templateFileUrl, std::string inFolder,
|
||||
std::string outFolder, std::string articleIdentifier)
|
||||
std::string outFolder, int flags, std::string articleIdentifier)
|
||||
{
|
||||
options = flags;
|
||||
this->outFolder = outFolder;
|
||||
this->inFolder = inFolder;
|
||||
pageTemplate = readFile(templateFileUrl);
|
||||
|
@ -68,7 +69,8 @@ std::string BlogPageBuilder::generateNavSection()
|
|||
buffer << "\n<h1>Navigation</h1>\n\n";
|
||||
for (Page* page : pages)
|
||||
{
|
||||
if (page->getPageFlags().hidden)
|
||||
if (page->getPageFlags().hidden &&
|
||||
isOptionEnabled(OptionFlags::HIDE_PRIVATE))
|
||||
continue;
|
||||
buffer
|
||||
<< "<li><a href=" << page->getRelativeUrl() << ">"
|
||||
|
@ -86,3 +88,8 @@ std::string BlogPageBuilder::readFile(std::string fileUrl)
|
|||
|
||||
return fileCache.str();
|
||||
}
|
||||
|
||||
bool BlogPageBuilder::isOptionEnabled(int flag)
|
||||
{
|
||||
return (options & flag) == flag;
|
||||
}
|
||||
|
|
|
@ -11,13 +11,21 @@
|
|||
|
||||
/*
|
||||
* Class that builds blog pages, takes a template page to put the blog-post in
|
||||
* along with an optional artifleIdentifier. The template is searched for this
|
||||
* along with an optional articleIdentifier. The template is searched for this
|
||||
* and the blog is placed after it.
|
||||
*/
|
||||
|
||||
class BlogPageBuilder
|
||||
{
|
||||
public:
|
||||
enum OptionFlags
|
||||
{
|
||||
NONE = 0X0,
|
||||
HIDE_PRIVATE = 0x1
|
||||
};
|
||||
private:
|
||||
int options;
|
||||
|
||||
std::string outFolder;
|
||||
std::string inFolder;
|
||||
|
||||
|
@ -36,11 +44,12 @@ private:
|
|||
|
||||
std::string generateNavSection();
|
||||
void createPage(Page* page);
|
||||
bool isOptionEnabled(int flag);
|
||||
|
||||
public:
|
||||
|
||||
BlogPageBuilder(std::string templateFileUrl, std::string inFolder, std::string outFolder,
|
||||
std::string articleIdentifier = "<article>");
|
||||
int flags, std::string articleIdentifier = "<article>");
|
||||
~BlogPageBuilder();
|
||||
|
||||
void buildAllPages();
|
||||
|
|
|
@ -45,8 +45,10 @@ std::string Page::getOutFileUrl()
|
|||
|
||||
std::string Page::getRelativeUrl()
|
||||
{
|
||||
std::string formattedTitle = findAndReplace(title, " ", "_");
|
||||
return "/" + formattedTitle + ".html";
|
||||
int start = sourceFileUrl.find_last_of("/");
|
||||
std::string relativeUrl = std::string(sourceFileUrl).substr(start, sourceFileUrl.length()-start);
|
||||
relativeUrl.replace(relativeUrl.length()-3, 3, ".html");
|
||||
return relativeUrl;
|
||||
}
|
||||
|
||||
FileFlags Page::getPageFlags()
|
||||
|
|
26
Src/blog.cpp
26
Src/blog.cpp
|
@ -23,7 +23,7 @@ std::string findAndReplace(std::string text, std::string find, std::string repla
|
|||
return text;
|
||||
}
|
||||
|
||||
std::string getArg(int argc, char* argv[], std::string argIdString)
|
||||
std::string getArgValue(int argc, char* argv[], std::string argIdString)
|
||||
{
|
||||
for (int i = 0; i < argc; i++)
|
||||
{
|
||||
|
@ -35,6 +35,16 @@ std::string getArg(int argc, char* argv[], std::string argIdString)
|
|||
return "";
|
||||
}
|
||||
|
||||
bool doesArgExist(int argc, char* argv[], std::string argIdString)
|
||||
{
|
||||
for (int i = 0; i < argc; i++)
|
||||
{
|
||||
if(strcmp(argv[i], argIdString.c_str()) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void copyFolderAndContents(std::string inUrl, std::string outUrl)
|
||||
{
|
||||
std::filesystem::copy_options opts = std::filesystem::copy_options::update_existing |
|
||||
|
@ -45,18 +55,22 @@ void copyFolderAndContents(std::string inUrl, std::string outUrl)
|
|||
/*
|
||||
* -in="" // give source folder
|
||||
* -out="" // give output folder
|
||||
* -hide // hides private posts
|
||||
*/
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::string source = getArg(argc, argv, "-in=");
|
||||
std::string source = getArgValue(argc, argv, "-in=");
|
||||
if (source == "")
|
||||
source = SOURCE_FILE_FOLDER;
|
||||
std::string output = getArg(argc, argv, "-out=");
|
||||
std::string output = getArgValue(argc, argv, "-out=");
|
||||
if (output == "")
|
||||
output = OUTPUT_FILE_FOLDER;
|
||||
int flags = BlogPageBuilder::OptionFlags::NONE;
|
||||
if (doesArgExist(argc, argv, "-hide"))
|
||||
flags |= BlogPageBuilder::OptionFlags::HIDE_PRIVATE;
|
||||
|
||||
// generated pages
|
||||
BlogPageBuilder* builder = new BlogPageBuilder(RESOURCE_FOLDER "/Templates/BlogPageTemplate.html", source, output);
|
||||
BlogPageBuilder* builder = new BlogPageBuilder(RESOURCE_FOLDER "/Templates/BlogPageTemplate.html", source, output, flags);
|
||||
builder->buildAllPages();
|
||||
|
||||
// pre-written pages and resources i.e. images
|
||||
|
@ -64,7 +78,5 @@ int main(int argc, char* argv[])
|
|||
|
||||
}
|
||||
|
||||
// TODO: get images and resources moved across to output
|
||||
// TODO: nav sections :eww:
|
||||
// TODO: copy static pages over
|
||||
// TODO: code doesnt copy moomin
|
||||
// TODO: custom file names with tag on md pages
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue