diff options
author | lns <matzeton@googlemail.com> | 2021-10-21 14:52:26 +0200 |
---|---|---|
committer | lns <matzeton@googlemail.com> | 2021-10-21 14:59:00 +0200 |
commit | 9266070e51422a71566ee5c04db42feec996c485 (patch) | |
tree | 4ff57de8bfce87bde001c80c7ab9fae3080aa248 /src/content/markdown/Markdown.cpp | |
parent | 384724a00be9dbb8f40d295f99b9c6bcfb48b387 (diff) |
Improved URI handling and redirection/routing.
* parse and process URI query strings
* remove garbage slashes from URI path / sanitize
* more template examples
Signed-off-by: lns <matzeton@googlemail.com>
Diffstat (limited to 'src/content/markdown/Markdown.cpp')
-rw-r--r-- | src/content/markdown/Markdown.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/content/markdown/Markdown.cpp b/src/content/markdown/Markdown.cpp index a85f333..903fcec 100644 --- a/src/content/markdown/Markdown.cpp +++ b/src/content/markdown/Markdown.cpp @@ -8,6 +8,11 @@ Markdown::Markdown(std::string uriBasePath, std::string markdownFilesPath, std:: m_MainTemplatePath(mainTemplatePath), m_MarkdownFilesPath(markdownFilesPath) { + if (m_MainTemplatePath.empty() == false) + { + m_Redirections.push_back(uriBasePath + "/"); + m_Redirections.push_back(uriBasePath + "/index.html"); + } } extern "C" void markdown_to_html_conversion(const MD_CHAR * const text, MD_SIZE size, void * const userdata) @@ -20,6 +25,10 @@ extern "C" void markdown_to_html_conversion(const MD_CHAR * const text, MD_SIZE bool Markdown::Init() { std::cout << "Markdown files path: " << m_MarkdownFilesPath << std::endl; + if (m_UriBasePath.empty() == false) + { + std::cout << "Markdown files URI base path: " << m_UriBasePath << std::endl; + } std::vector<std::string> extensions = {"md"}; @@ -68,15 +77,35 @@ bool Markdown::Render(RequestResponse & rr, RenderData & rd, std::string & out) (void)rd; (void)out; + std::string md_file; + if (m_MainTemplatePath.empty() == true) { return false; } - return false; /* TODO: Make markdown module usable as standalone module?! */ + if (rr.GetUriPath() == m_UriBasePath || rr.GetUriPath() == m_UriBasePath + "/" || + rr.GetUriPath() == m_UriBasePath + "/index.html") + { + rr.UseUri(); + if (rr.QueryValueEquals("get", "bla") == true) + { + rd["content"] = "bla"; + } + else + { + rd["content"] = "blubb"; + } + } + else + { + return false; + } + + return true; } -std::string const & Markdown::GetUriBasePath() const +std::string & Markdown::GetUriBasePath() { return m_UriBasePath; } @@ -86,7 +115,7 @@ std::string const & Markdown::GetMainTemplate() const return m_MainTemplatePath; } -Redirections const & Markdown::GetRedirections() const +Redirections & Markdown::GetRedirections() { return m_Redirections; } |