#include #include #include #include #include "crow_all.h" std::string exec(const std::string &cmd) { std::array buffer; std::string result; std::unique_ptr pipe(popen(cmd.c_str(), "r"), pclose); if (!pipe) { throw std::runtime_error("popen() failed!"); } while (fgets(buffer.data(), static_cast(buffer.size()), pipe.get()) != nullptr) { result += buffer.data(); } return result; } int main() { crow::SimpleApp app; CROW_ROUTE(app, "/")([](){ return crow::mustache::load_text("index.html"); }); CROW_ROUTE(app, "/blog")([](){ std::string posts = ""; std::filesystem::path postsDir("posts"); for (auto const& entry : std::filesystem::directory_iterator{postsDir}) { posts.append("
  • "); posts.append(entry.path().filename()); posts.append("
  • "); } auto page = crow::mustache::load("posts.html"); crow::mustache::context ctx( {{"posts", posts}} ); return page.render(ctx); }); CROW_ROUTE(app, "/blog/")([](const std::string &name){ return exec("pandoc --standalone --template templates/template.html ./posts/" + name); }); app.port(8080).multithreaded().run(); }