diff options
Diffstat (limited to 'web/src')
| -rw-r--r-- | web/src/handlers.cpp | 31 | ||||
| -rw-r--r-- | web/src/handlers.hpp | 7 | ||||
| -rw-r--r-- | web/src/main.cpp | 5 |
3 files changed, 43 insertions, 0 deletions
diff --git a/web/src/handlers.cpp b/web/src/handlers.cpp new file mode 100644 index 0000000..1dfeb81 --- /dev/null +++ b/web/src/handlers.cpp @@ -0,0 +1,31 @@ +#include "handlers.hpp" + +#include <fstream> +#include <memory> +#include <string> + +#include "crow/http_response.h" +#include "crow/mustache.h" +#include "maddy/parser.h" + +namespace botweb { + crow::response get_wiki_page(const std::string &path) { + std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>(); + + std::ifstream contents("docs/" + path + ".md"); + std::string contents_html = parser->Parse(contents); + contents.close(); + + std::ifstream summary("docs/summary.md"); + std::string summary_html = parser->Parse(summary); + summary.close(); + + auto page = crow::mustache::load("wiki_page.html"); + + crow::mustache::context ctx; + ctx["content"] = contents_html; + ctx["summary"] = summary_html; + + return crow::response(200, page.render(ctx)); + } +} diff --git a/web/src/handlers.hpp b/web/src/handlers.hpp new file mode 100644 index 0000000..d150e6d --- /dev/null +++ b/web/src/handlers.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "crow/http_response.h" + +namespace botweb { + crow::response get_wiki_page(const std::string &path); +} diff --git a/web/src/main.cpp b/web/src/main.cpp index 700e71a..06936c5 100644 --- a/web/src/main.cpp +++ b/web/src/main.cpp @@ -1,5 +1,6 @@ #include "crow/app.h" #include "crow/mustache.h" +#include "handlers.hpp" int main(int argc, char *argv[]) { crow::SimpleApp app; @@ -11,6 +12,10 @@ int main(int argc, char *argv[]) { return page.render(); }); + CROW_ROUTE(app, "/wiki")([]() { return botweb::get_wiki_page("/README"); }); + CROW_ROUTE(app, "/wiki/<path>") + ([](const std::string &path) { return botweb::get_wiki_page(path); }); + app.multithreaded().port(18083).run(); return 0; } |
