summaryrefslogtreecommitdiff
path: root/web/src/handlers.cpp
blob: 03cddd9086ec73ddcf233ed1d92e961fcd38fa2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "handlers.hpp"

#include <fstream>
#include <memory>
#include <optional>
#include <string>

#include "config.hpp"
#include "crow/http_response.h"
#include "crow/mustache.h"
#include "maddy/parser.h"

namespace botweb {
  crow::response get_wiki_page(const std::string &path,
                               const std::optional<Configuration> &cfg) {
    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;
    ctx["contact_url"] = (*cfg).contact_url;
    ctx["contact_name"] = (*cfg).contact_name;

    return crow::response(200, page.render(ctx));
  }
}