Adds arguments for input and output files

Adds gitignore
This commit is contained in:
Rosia E Evans 2023-09-28 13:21:49 +01:00
parent a217ace469
commit 202801841d
36 changed files with 148 additions and 502 deletions

View file

@ -4,6 +4,8 @@
BlogPageBuilder::BlogPageBuilder(std::string templateFileUrl, std::string inFolder,
std::string outFolder, std::string articleIdentifier)
{
this->outFolder = outFolder;
this->inFolder = inFolder;
pageTemplate = readFile(templateFileUrl);
this->articleIdentifier = articleIdentifier;
navIdentifier = "<nav>";
@ -53,10 +55,10 @@ int BlogPageBuilder::calculateIdentifierLocation(std::string id, std::string tex
void BlogPageBuilder::collectPages()
{
auto directoryIterator = std::filesystem::directory_iterator(SOURCE_FILE_FOLDER);
auto directoryIterator = std::filesystem::directory_iterator(inFolder);
for(auto file : directoryIterator)
{
pages.push_back(new Page(file.path(), OUTPUT_FILE_FOLDER));
pages.push_back(new Page(file.path(), outFolder));
}
}

View file

@ -1,5 +1,4 @@
#pragma once
#include "../MacroDefinitions.h"
#include <string>
#include <fstream>
@ -19,6 +18,9 @@
class BlogPageBuilder
{
private:
std::string outFolder;
std::string inFolder;
std::string pageTemplate;
std::string articleIdentifier;
std::string navIdentifier;

View file

@ -15,4 +15,7 @@ target_link_libraries(blog PUBLIC md4c-html)
target_link_libraries(blog PRIVATE BlogParser)
target_link_libraries(blog PRIVATE BlogPageBuilder)
target_include_directories(blog PUBLIC "${PROJECT_BINARY_DIR}")
target_include_directories(BlogPageBuilder PUBLIC "${PROJECT_BINARY_DIR}")
target_include_directories(BlogParser PUBLIC "${PROJECT_BINARY_DIR}")
# This probably needs a severe clean up

View file

@ -91,7 +91,7 @@ void Page::writePageToFile()
file.close();
if (file.fail())
printf("failed to write file");
printf("failed to write file to %s \n", outFileUrl.c_str());
}

View file

@ -1,18 +1,49 @@
#include "../MacroDefinitions.h"
#include "MacroDefinitions.h"
#include <string>
#include <fstream>
#include <cstring>
#include "BlogPageBuilder.h"
std::string findAndReplace(std::string text, std::string find, std::string replace)
{
int pos = 0;
while (true)
{
pos = text.find(find, pos+1);
if (pos == std::string::npos)
break;
text.replace(pos, 1, replace);
}
return text;
}
std::string getArg(int argc, char* argv[], std::string argIdString)
{
for (int i = 0; i < argc; i++)
{
int idValSplit = argIdString.length()-1;
const char* argId = argIdString.c_str();
if (strncmp(argId, argv[i], idValSplit) == 0)
return std::string(argv[i]).substr(idValSplit+1, strlen(argv[i])-(idValSplit+1));
}
return "";
}
/*
* -in="" // give source folder
* -out="" // give output folder
*/
int main(int argc, char* argv[])
{
std::string source = argv[1];
if (source == "");
std::string source = getArg(argc, argv, "-in=");
if (source == "")
source = SOURCE_FILE_FOLDER;
std::string output = argv[2];
std::string output = getArg(argc, argv, "-out=");
if (output == "")
output = OUTPUT_FILE_FOLDER;