diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2021-10-22 17:25:04 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2021-10-22 17:25:04 +0200 |
commit | e9d684f5b5cfea813c168a59c0fe087d5456a444 (patch) | |
tree | 7c6fb0dcfaa42f86b3cf7a6c78f63c55fbdff770 | |
parent | 9266070e51422a71566ee5c04db42feec996c485 (diff) |
Get request query value.
* Markdown module query processing and HTML output.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r-- | pages/index.md | 1 | ||||
-rw-r--r-- | src/EventManager.cpp | 2 | ||||
-rw-r--r-- | src/RequestResponse.cpp | 27 | ||||
-rw-r--r-- | src/RequestResponse.hpp | 6 | ||||
-rw-r--r-- | src/content/markdown/Markdown.cpp | 21 | ||||
-rw-r--r-- | wwwroot/index.html | 3 |
6 files changed, 52 insertions, 8 deletions
diff --git a/pages/index.md b/pages/index.md index fbb8dc4..99bd385 100644 --- a/pages/index.md +++ b/pages/index.md @@ -1 +1,2 @@ *Just HTML* +~~plaintext~~ diff --git a/src/EventManager.cpp b/src/EventManager.cpp index 2f2da36..1faea6d 100644 --- a/src/EventManager.cpp +++ b/src/EventManager.cpp @@ -63,7 +63,7 @@ extern "C" GenerateInternalErrorPage(req, "EvContentManagerInterceptor: path == nullptr"); return; } -#if 1 +#if 0 std::cout << "URI Path: " << path << std::endl; #endif diff --git a/src/RequestResponse.cpp b/src/RequestResponse.cpp index c3247e9..535de78 100644 --- a/src/RequestResponse.cpp +++ b/src/RequestResponse.cpp @@ -73,7 +73,32 @@ bool RequestResponse::GetInputHeader(std::string const key, std::string value) return GetInputHeaderByRef(key, value); } -bool RequestResponse::QueryValueEquals(std::string key, std::string value) +bool RequestResponse::GetQueryValue(std::string & key, std::string & value) +{ + std::string const k = key; + return GetQueryValue(k, value); +} + +bool RequestResponse::GetQueryValue(std::string const key, std::string & value) +{ + char const * const v = evhttp_find_header(&m_Query, key.c_str()); + + if (v == nullptr) + { + return false; + } + + value = v; + return true; +} + +bool RequestResponse::QueryValueEquals(std::string & key, std::string value) +{ + std::string const k = key; + return QueryValueEquals(k, value); +} + +bool RequestResponse::QueryValueEquals(std::string const key, std::string value) { char const * const v = evhttp_find_header(&m_Query, key.c_str()); diff --git a/src/RequestResponse.hpp b/src/RequestResponse.hpp index 3dccd54..d3d3551 100644 --- a/src/RequestResponse.hpp +++ b/src/RequestResponse.hpp @@ -30,7 +30,11 @@ public: bool GetInputHeaderByRef(std::string const & key, std::string & value); bool GetInputHeader(std::string const key, std::string value); - bool QueryValueEquals(std::string key, std::string value); + bool GetQueryValue(std::string & key, std::string & value); + bool GetQueryValue(std::string const key, std::string & value); + + bool QueryValueEquals(std::string & key, std::string value); + bool QueryValueEquals(std::string const key, std::string value); private: char const * const m_UriPath; diff --git a/src/content/markdown/Markdown.cpp b/src/content/markdown/Markdown.cpp index 903fcec..2b0bcc6 100644 --- a/src/content/markdown/Markdown.cpp +++ b/src/content/markdown/Markdown.cpp @@ -88,13 +88,26 @@ bool Markdown::Render(RequestResponse & rr, RenderData & rd, std::string & out) rr.GetUriPath() == m_UriBasePath + "/index.html") { rr.UseUri(); - if (rr.QueryValueEquals("get", "bla") == true) + std::string requested_markdown; + + rd["uri"] = rr.GetUriPath(); + if (rr.GetQueryValue("get", requested_markdown) == true) { - rd["content"] = "bla"; + requested_markdown += ".md"; + if (HasMarkdownFile(requested_markdown) == true) + { + rd["content"] = *GetMarkdownHTML(requested_markdown); + } else if (HasMarkdownFile("index.md") == true) { + rd["content"] = *GetMarkdownHTML("index.md"); + } else { + return false; + } } - else + else if (HasMarkdownFile("index.md") == true) { - rd["content"] = "blubb"; + rd["content"] = *GetMarkdownHTML("index.md"); + } else { + return false; } } else diff --git a/wwwroot/index.html b/wwwroot/index.html index 9b05eee..07dd49d 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -1,4 +1,5 @@ <html><body> <b>INDEX TMPL</b> - {{ content }} + {{ uri }}<br> + {{ indent(content, 4, false, false) }} </body></html> |