diff options
| -rw-r--r-- | static/styles/wiki-content.css | 59 | ||||
| -rw-r--r-- | static/styles/wiki-sidebar.css | 35 | ||||
| -rw-r--r-- | templates/wiki_page.html | 35 | ||||
| -rw-r--r-- | web/src/handlers.cpp | 31 | ||||
| -rw-r--r-- | web/src/handlers.hpp | 7 | ||||
| -rw-r--r-- | web/src/main.cpp | 5 |
6 files changed, 172 insertions, 0 deletions
diff --git a/static/styles/wiki-content.css b/static/styles/wiki-content.css new file mode 100644 index 0000000..22aad11 --- /dev/null +++ b/static/styles/wiki-content.css @@ -0,0 +1,59 @@ +.wiki-content { + margin: 0 16px; + margin-bottom: 64px; +} + +.wiki-content h1 { + font-size: 32px; + font-weight: 600; +} + +.wiki-content h2 { + font-size: 24px; + font-weight: 600; +} + +.wiki-content h3 { + font-size: 24px; +} + +.wiki-content h1, .wiki-content h2, .wiki-content h3 { + margin: 16px 0; +} + +.wiki-content p { + margin: 0 16px; +} + +.wiki-content ul { + margin: 0 32px; +} + +.wiki-content li { + list-style-type: disc; +} + +.wiki-content a { + color: rgb(4, 120, 87); + text-decoration: underline; +} + +.wiki-content a:hover { + color: rgb(16, 185, 129); +} + +.wiki-content code { + background-color: rgba(243, 244, 246, 255); + color: rgba(5, 150, 105, 255); + padding: 2px; + border-radius: 2px; +} + +.wiki-content blockquote { + background-color: rgba(243, 244, 246, 255); + padding: 2px; + margin: 16px 0; + + border-left-width: 4px; + border-color: rgba(5, 150, 105, 255); +} diff --git a/static/styles/wiki-sidebar.css b/static/styles/wiki-sidebar.css new file mode 100644 index 0000000..fc927df --- /dev/null +++ b/static/styles/wiki-sidebar.css @@ -0,0 +1,35 @@ +.wiki-sidebar { + min-width: 256px; +} + +.wiki-sidebar h1 { + font-size: 20px; + font-weight: 600; +} + +.wiki-sidebar h2 { + font-size: 18px; + font-weight: 600; + margin-left: 4px; +} + +.wiki-sidebar h1, .wiki-sidebar h2 { + margin-top: 4px; + margin-bottom: 4px; +} + + +.wiki-sidebar ul { + margin: 0 8px; +} + +.wiki-sidebar li {} + +.wiki-sidebar a { + color: rgb(4, 120, 87); + text-decoration: underline; +} + +.wiki-sidebar a:hover { + color: rgb(16, 185, 129); +} diff --git a/templates/wiki_page.html b/templates/wiki_page.html new file mode 100644 index 0000000..87de1e4 --- /dev/null +++ b/templates/wiki_page.html @@ -0,0 +1,35 @@ +<!DOCTYPE> +<html> + <head> + <link rel="stylesheet" type="text/css" href="/static/style.css"> + <link rel="stylesheet" type="text/css" href="/static/styles/wiki-sidebar.css"> + <link rel="stylesheet" type="text/css" href="/static/styles/wiki-content.css"> + </head> + <body> + <div class="min-h-screen w-full flex items-center flex-col"> + <div class="lg:w-1/2 w-full flex items-center flex-col"> + {{> header.html }} + + <!-- Header --> + <div class="w-full p-2 mt-4 bg-gradient-to-t from-green-400 to-green-200"> + <h1 class="mx-4 text-xl font-zilla font-semibold"> + <i class="fa-solid fa-book"></i> Wiki + </h1> + </div> + + <!-- Wiki page --> + <div class="w-full min-h-screen flex flex-col-reverse lg:flex-row"> + <!-- Sidebar --> + <div class="wiki-sidebar flex flex-col lg:sticky lg:top-0 overflow-y-scroll px-6 lg:max-h-screen bg-gray-50"> + {{{ summary }}} + </div> + <!-- Content --> + <div class="wiki-content"> + {{{ content }}} + </div> + </div> + </div> + + {{> footer.html }} + </body> +</html> 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; } |
