Fix up build and start site generator.

This commit is contained in:
jmsgrogan 2022-10-03 07:45:10 +01:00
parent d471609712
commit bd60a28eef
15 changed files with 267 additions and 96 deletions

View file

@ -27,4 +27,14 @@ target_link_libraries(sample_console PUBLIC console core network
database geometry audio web)
set_property(TARGET sample_console PROPERTY FOLDER apps)
set_property(TARGET sample_gui PROPERTY FOLDER apps)
set_property(TARGET sample_gui PROPERTY FOLDER apps)
# Website Generator
add_executable(website_generator website-generator.cpp)
#target_include_directories(website_generator PUBLIC
# "${PROJECT_SOURCE_DIR}/src/console"
# )
target_link_libraries(website_generator PUBLIC core web)
set_property(TARGET website_generator PROPERTY FOLDER apps)

129
apps/website-generator.cpp Normal file
View file

@ -0,0 +1,129 @@
#include "CommandLineArgs.h"
#include <string>
#include <iostream>
#include <vector>
#include <filesystem>
class GeneratorConfig
{
};
class ContentPage
{
public:
ContentPage(const std::string& filename)
: mFilename(filename)
{
}
std::string getFilename() const
{
return mFilename;
}
private:
std::string mFilename;
};
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()
{
const auto content_dir = mProjectPath / "content";
if (std::filesystem::is_directory(content_dir))
{
std::cout << "checking " << content_dir << std::endl;
const auto pages_dir = content_dir / "pages";
if (std::filesystem::is_directory(pages_dir))
{
std::cout << "checking " << pages_dir << std::endl;
for (const auto& entry : std::filesystem::directory_iterator(pages_dir))
{
if (std::filesystem::is_regular_file(entry) && entry.path().extension() == ".md")
{
mPages.push_back(ContentPage(entry.path()));
}
}
}
}
else
{
std::cout << "nope in " << content_dir << std::endl;
}
for(const auto& page : mPages)
{
std::cout << "Got page " << page.getFilename() << std::endl;
}
}
void parseTemplateFiles()
{
}
void doSubstitutions()
{
}
void write()
{
}
private:
std::filesystem::path mProjectPath;
GeneratorConfig mConfig;
std::vector<ContentPage> mPages;
};
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;
}