Break web generator to own cmake.
This commit is contained in:
parent
bd60a28eef
commit
ebd41bf4ee
14 changed files with 121 additions and 45 deletions
18
apps/website-generator/CMakeLists.txt
Normal file
18
apps/website-generator/CMakeLists.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
|
||||
list(APPEND website_generator_LIB_INCLUDES
|
||||
ContentFile.h
|
||||
ContentFile.cpp
|
||||
MarkdownContentParser.h
|
||||
MarkdownContentParser.cpp)
|
||||
|
||||
|
||||
add_executable(website_generator main.cpp ${website_generator_LIB_INCLUDES})
|
||||
|
||||
target_include_directories(website_generator PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
)
|
||||
|
||||
target_link_libraries(website_generator PUBLIC core web)
|
||||
|
||||
set_property(TARGET website_generator PROPERTY FOLDER apps/website-generator)
|
||||
|
0
apps/website-generator/ContentFile.cpp
Normal file
0
apps/website-generator/ContentFile.cpp
Normal file
0
apps/website-generator/ContentFile.h
Normal file
0
apps/website-generator/ContentFile.h
Normal file
0
apps/website-generator/MarkdownContentParser.cpp
Normal file
0
apps/website-generator/MarkdownContentParser.cpp
Normal file
0
apps/website-generator/MarkdownContentParser.h
Normal file
0
apps/website-generator/MarkdownContentParser.h
Normal file
162
apps/website-generator/main.cpp
Normal file
162
apps/website-generator/main.cpp
Normal file
|
@ -0,0 +1,162 @@
|
|||
#include "CommandLineArgs.h"
|
||||
|
||||
#include "Directory.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
class GeneratorConfig
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class ContentFile
|
||||
{
|
||||
public:
|
||||
|
||||
ContentFile(const std::string& filename)
|
||||
: mFilename(filename)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string getFilename() const
|
||||
{
|
||||
return mFilename;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string mFilename;
|
||||
};
|
||||
|
||||
class ContentPage : public ContentFile
|
||||
{
|
||||
public:
|
||||
|
||||
ContentPage(const std::string& filename)
|
||||
: ContentFile(filename)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class ContentArticle : public ContentFile
|
||||
{
|
||||
public:
|
||||
|
||||
ContentArticle(const std::string& filename)
|
||||
: ContentFile(filename)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
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 pages_files = Directory::getFilesWithExtension(getPagesPath(), ".md");
|
||||
for (const auto& path : pages_files)
|
||||
{
|
||||
mPages.push_back(ContentPage(path));
|
||||
}
|
||||
|
||||
const auto article_files = Directory::getFilesWithExtension(getArticlesPath(), ".md");
|
||||
for (const auto& path : article_files)
|
||||
{
|
||||
mArticles.push_back(ContentArticle(path));
|
||||
}
|
||||
|
||||
for(const auto& page : mPages)
|
||||
{
|
||||
std::cout << "Got page " << page.getFilename() << std::endl;
|
||||
}
|
||||
|
||||
for(const auto& article : mArticles)
|
||||
{
|
||||
std::cout << "Got article " << article.getFilename() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void parseTemplateFiles()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void doSubstitutions()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void write()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Path getContentPath() const
|
||||
{
|
||||
return mProjectPath / "content";
|
||||
}
|
||||
|
||||
Path getPagesPath() const
|
||||
{
|
||||
return getContentPath() / "pages";
|
||||
}
|
||||
|
||||
Path getArticlesPath() const
|
||||
{
|
||||
return getContentPath() / "articles";
|
||||
}
|
||||
|
||||
std::filesystem::path mProjectPath;
|
||||
GeneratorConfig mConfig;
|
||||
std::vector<ContentPage> mPages;
|
||||
std::vector<ContentArticle> mArticles;
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue