stuff-from-scratch/apps/website-generator/main.cpp

163 lines
2.7 KiB
C++
Raw Normal View History

2022-10-03 06:45:10 +00:00
#include "CommandLineArgs.h"
2022-10-03 07:12:38 +00:00
#include "Directory.h"
2022-10-03 06:45:10 +00:00
#include <string>
#include <iostream>
#include <vector>
#include <filesystem>
class GeneratorConfig
{
};
2022-10-03 07:12:38 +00:00
class ContentFile
2022-10-03 06:45:10 +00:00
{
public:
2022-10-03 07:12:38 +00:00
ContentFile(const std::string& filename)
2022-10-03 06:45:10 +00:00
: mFilename(filename)
{
}
std::string getFilename() const
{
return mFilename;
}
2022-10-03 07:12:38 +00:00
protected:
2022-10-03 06:45:10 +00:00
std::string mFilename;
};
2022-10-03 07:12:38 +00:00
class ContentPage : public ContentFile
{
public:
ContentPage(const std::string& filename)
: ContentFile(filename)
{
}
};
class ContentArticle : public ContentFile
{
public:
ContentArticle(const std::string& filename)
: ContentFile(filename)
{
}
};
2022-10-03 06:45:10 +00:00
class WebsiteGenerator
{
public:
void findProject(const std::string& searchPath)
{
const auto config_path = std::filesystem::path(searchPath) / "config.toml";
if (std::filesystem::exists(config_path))
{
mProjectPath = searchPath;
std::cout << "Found config.toml in " << searchPath << std::endl;
}
}
void readConfig()
{
}
void parseContentFiles()
{
2022-10-03 07:12:38 +00:00
const auto pages_files = Directory::getFilesWithExtension(getPagesPath(), ".md");
for (const auto& path : pages_files)
2022-10-03 06:45:10 +00:00
{
2022-10-03 07:12:38 +00:00
mPages.push_back(ContentPage(path));
2022-10-03 06:45:10 +00:00
}
2022-10-03 07:12:38 +00:00
const auto article_files = Directory::getFilesWithExtension(getArticlesPath(), ".md");
for (const auto& path : article_files)
2022-10-03 06:45:10 +00:00
{
2022-10-03 07:12:38 +00:00
mArticles.push_back(ContentArticle(path));
2022-10-03 06:45:10 +00:00
}
for(const auto& page : mPages)
{
std::cout << "Got page " << page.getFilename() << std::endl;
}
2022-10-03 07:12:38 +00:00
for(const auto& article : mArticles)
{
std::cout << "Got article " << article.getFilename() << std::endl;
}
2022-10-03 06:45:10 +00:00
}
void parseTemplateFiles()
{
}
void doSubstitutions()
{
}
void write()
{
}
private:
2022-10-03 07:12:38 +00:00
Path getContentPath() const
{
return mProjectPath / "content";
}
Path getPagesPath() const
{
return getContentPath() / "pages";
}
Path getArticlesPath() const
{
return getContentPath() / "articles";
}
2022-10-03 06:45:10 +00:00
std::filesystem::path mProjectPath;
GeneratorConfig mConfig;
std::vector<ContentPage> mPages;
2022-10-03 07:12:38 +00:00
std::vector<ContentArticle> mArticles;
2022-10-03 06:45:10 +00:00
};
int main(int argc, char *argv[])
{
auto args = CommandLineArgs::Create();
args->process(argc, argv);
args->recordLaunchPath();
WebsiteGenerator generator;
generator.findProject(args->getArg(1));
generator.readConfig();
// Find and process project files
generator.parseContentFiles();
// Find template files
// Substitute template files
return 0;
}