From e14de692710bfcb18f3eff662839de14c2404563 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sat, 6 Jan 2024 16:35:23 +0400 Subject: [PATCH] The page template is embedded in the error response This is a shortcut change since it doesn't make sense to send the error page template with every error response (the viewer can fetch it from the server once but that's slightly more work). --- src/server/response.cpp | 1 + static/templates/error.html | 1 + test/response.cpp | 2 ++ 3 files changed, 4 insertions(+) diff --git a/src/server/response.cpp b/src/server/response.cpp index efb72a9c9..df3dc10ef 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -305,6 +305,7 @@ std::unique_ptr ContentResponseBlueprint::generateResponseObjec { kainjow::mustache::data d = m_data->toMustache(m_request.get_user_language()); if ( m_includeKiwixResponseData ) { + d.set("KIWIX_RESPONSE_TEMPLATE", escapeForJSON(m_template)); d.set("KIWIX_RESPONSE_DATA", m_data->asJSON()); } auto r = ContentResponse::build(m_template, d, m_mimeType); diff --git a/static/templates/error.html b/static/templates/error.html index 717e56b27..66486b6ba 100644 --- a/static/templates/error.html +++ b/static/templates/error.html @@ -6,6 +6,7 @@ {{#CSS_URL}} {{/CSS_URL}}{{#KIWIX_RESPONSE_DATA}} {{/KIWIX_RESPONSE_DATA}} diff --git a/test/response.cpp b/test/response.cpp index 5762f8319..61f92ab75 100644 --- a/test/response.cpp +++ b/test/response.cpp @@ -46,6 +46,7 @@ R"( Content not found {{/KIWIX_RESPONSE_DATA}}\n \n \n

{{PAGE_HEADING}}

\n{{#details}}\n

\n {{{p}}}\n

\n{{/details}}\n \n\n"; const KIWIX_RESPONSE_DATA = { "CSS_URL" : "/css/error.css", "PAGE_HEADING" : { "msgid" : "404-page-heading", "params" : { } }, "PAGE_TITLE" : { "msgid" : "404-page-title", "params" : { } }, "details" : [ { "p" : { "msgid" : "suggest-search", "params" : { "PATTERN" : "asdf", "SEARCH_URL" : "/search?q=asdf" } } } ] }; @@ -85,6 +86,7 @@ R"( [I18N TESTING] Not Found - Try Again {{/KIWIX_RESPONSE_DATA}}\n \n \n

{{PAGE_HEADING}}

\n{{#details}}\n

\n {{{p}}}\n

\n{{/details}}\n \n\n"; const KIWIX_RESPONSE_DATA = { "CSS_URL" : "/css/error.css", "PAGE_HEADING" : { "msgid" : "404-page-heading", "params" : { } }, "PAGE_TITLE" : { "msgid" : "404-page-title", "params" : { } }, "details" : [ { "p" : { "msgid" : "suggest-search", "params" : { "PATTERN" : "asdf", "SEARCH_URL" : "/search?q=asdf" } } } ] };