Blog/Src/blog.cpp

102 lines
2.6 KiB
C++
Raw Normal View History

// #include "MacroDefinitions.h"
#include <string>
#include <fstream>
#include <cstring>
#include <filesystem>
#include <iostream>
2024-08-08 11:41:42 +01:00
#include "Program.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 getArgValue(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));
}
2025-05-30 00:34:28 +01:00
printf("Missing argument! %s", argIdString);
return std::string("")
}
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 |
std::filesystem::copy_options::recursive;
std::filesystem::copy(inUrl, outUrl, opts);
}
void checkForEmptyArguments()
{
// I hate doing it like this
2025-05-30 00:34:28 +01:00
if (source.empty() ||
output.empty() ||
stat.empty() ||
siteWebUrl.empty() ||
blogTemplate.empty() ||
atomTemplate.empty())
{
exit(0);
}
}
/*
* -in="" // give source folder
* -out="" // give output folder
* -static="" // give static resources folder (images and things to copy across to output folder go in here)
* -hide // hides private posts
*/
int main(int argc, char* argv[])
{
std::string source = getArgValue(argc, argv, "-in=");
std::string output = getArgValue(argc, argv, "-out=");
std::string stat = getArgValue(argc, argv, "-static=");
2024-08-08 11:41:42 +01:00
std::string siteWebUrl = getArgValue(argc, argv, "-url=");
std::string blogTemplate = getArgValue(argc, argv, "-blogTemplate=");
std::string atomTemplate = getArgValue(argc, argv, "-atomTemplate=");
checkForEmptyArguments()
int flags = OptionFlags::NONE;
if (doesArgExist(argc, argv, "-hide"))
flags |= OptionFlags::HIDE_PRIVATE;
Program* program = new Program(source, output, blogTemplate, atomTemplate, siteWebUrl, flags);
2024-08-08 11:41:42 +01:00
program->buildAll();
// pre-written pages and resources i.e. images
copyFolderAndContents(stat, output);
printf("Enjoy your website :)");
}
2023-09-28 15:17:51 +01:00
// TODO: nav sections :eww: