summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-04-24 17:15:05 +0200
committerRoland Reichwein <mail@reichwein.it>2020-04-24 17:15:05 +0200
commit58da9654563d89039a58e4bf14a3b0e383fe93c8 (patch)
treeafde44be6c0885cdfdd03ddd9ac74e6a02236473
parent1b6682c78518228b705cab2afd5a9eb595a90bbd (diff)
Fix impressum link
-rw-r--r--plugins/weblog/weblog.cpp25
-rw-r--r--response.cpp2
2 files changed, 16 insertions, 11 deletions
diff --git a/plugins/weblog/weblog.cpp b/plugins/weblog/weblog.cpp
index 92162db..7ace0fb 100644
--- a/plugins/weblog/weblog.cpp
+++ b/plugins/weblog/weblog.cpp
@@ -238,13 +238,18 @@ namespace {
class HtmlPage
{
- static const std::string header;
- static const std::string footer;
-
+ std::function<std::string(const std::string& key)>& mGetRequestParam;
std::string mContents;
+ std::string mHeader;
+ const std::string mFooter;
public:
- HtmlPage(std::string s = ""s): mContents(s)
+ HtmlPage(std::function<std::string(const std::string& key)>& GetRequestParam,
+ std::string s = ""s)
+ : mGetRequestParam(GetRequestParam)
+ , mContents(s)
+ , mHeader("<!DOCTYPE html><html><head><meta charset=\"utf-8\"/></head><body>")
+ , mFooter("<br/><br/><br/><a href=\"" + mGetRequestParam("plugin_path") + "/impressum.html\">Impressum, Datenschutzerklärung</a></body></html>")
{
}
@@ -256,19 +261,16 @@ namespace {
operator std::string() const
{
- return header + mContents + footer;
+ return mHeader + mContents + mFooter;
}
};
-
- const std::string HtmlPage::header{"<!DOCTYPE html><html><head><meta charset=\"utf-8\"/></head><body>"};
- const std::string HtmlPage::footer{"<br/><br/><br/><a href=\"impressum.html\">Impressum, Datenschutzerklärung</a></body></html>"};
std::string generateIndexPage(fs::path& path,
std::function<std::string(const std::string& key)>& GetRequestParam,
std::function<plugin_interface_setter_type>& SetResponseHeader)
{
try {
- HtmlPage htmlPage{"<h1>"s + GetRequestParam("WEBLOG_NAME") + "</h1>"s};
+ HtmlPage htmlPage{GetRequestParam, "<h1>"s + GetRequestParam("WEBLOG_NAME") + "</h1>"s};
fs::path link{ GetRequestParam("rel_target")};
@@ -292,6 +294,7 @@ namespace {
}
std::string generateArticlePage(fs::path& path,
+ std::function<std::string(const std::string& key)>& GetRequestParam,
std::function<plugin_interface_setter_type>& SetResponseHeader)
{
try {
@@ -309,7 +312,7 @@ namespace {
if (it != metaData.end() && it->second == "text/plain")
data = verbatimText(data);
- HtmlPage htmlPage{"<h1>"s + metaData.at("Subject") + "</h1>"s + metaData.at("Date") + "<br/><br/>"s + data};
+ HtmlPage htmlPage{GetRequestParam, "<h1>"s + metaData.at("Subject") + "</h1>"s + metaData.at("Date") + "<br/><br/>"s + data};
return htmlPage;
} catch (const std::exception& ex) {
@@ -381,7 +384,7 @@ std::string weblog_plugin::generate_page(
return generateIndexPage(path, GetRequestParam, SetResponseHeader);
if (is_article_page(rel_target, path))
- return generateArticlePage(path, SetResponseHeader);
+ return generateArticlePage(path, GetRequestParam, SetResponseHeader);
if (is_index_file(rel_target, path) || is_article_file(rel_target, path))
return generateStaticFile(path, SetResponseHeader);
diff --git a/response.cpp b/response.cpp
index 51c9603..7bbcebf 100644
--- a/response.cpp
+++ b/response.cpp
@@ -129,6 +129,8 @@ std::unordered_map<std::string, std::function<std::string(RequestContext&)>> Get
{"method", [](RequestContext& req_ctx) { return std::string{req_ctx.GetReq().method_string()};}},
+ {"plugin_path", [](RequestContext& req_ctx) { return std::string{req_ctx.GetPluginPath()};}},
+
{"rel_target", [](RequestContext& req_ctx) {return req_ctx.GetRelativePath();}},
{"target", [](RequestContext& req_ctx) {return req_ctx.GetTarget();}},