diff --git a/src/server/response.cpp b/src/server/response.cpp index 87de940c..50fd7b4a 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -243,6 +243,11 @@ public: }; } + static Data fromMsgId(const std::string& nonParameterizedMsgId) + { + return from(nonParameterizedMessage(nonParameterizedMsgId)); + } + std::string asJSON() const; void dumpJSON(std::ostream& os) const; @@ -375,11 +380,13 @@ NewHTTP404Response::NewHTTP404Response(const RequestContext& request, MHD_HTTP_NOT_FOUND, "text/html; charset=utf-8", RESOURCE::templates::sexy404_html, - /*includeKiwixResponseData=*/false) + /*includeKiwixResponseData=*/true) { *this->m_data = Data(Data::Object{ {"root", root }, - {"url_path", urlPath} + {"url_path", urlPath}, + {"PAGE_TITLE", Data::fromMsgId("new-404-page-title")}, + {"PAGE_HEADING", Data::fromMsgId("new-404-page-heading")}, }); } @@ -398,8 +405,8 @@ HTTPErrorResponse::HTTPErrorResponse(const RequestContext& request, Data::List emptyList; *this->m_data = Data(Data::Object{ {"CSS_URL", Data::onlyAsNonEmptyValue(cssUrl) }, - {"PAGE_TITLE", Data::from(nonParameterizedMessage(pageTitleMsgId))}, - {"PAGE_HEADING", Data::from(nonParameterizedMessage(headingMsgId))}, + {"PAGE_TITLE", Data::fromMsgId(pageTitleMsgId)}, + {"PAGE_HEADING", Data::fromMsgId(headingMsgId)}, {"details", emptyList} }); } diff --git a/static/skin/i18n/en.json b/static/skin/i18n/en.json index 09ca32d1..ec398c02 100644 --- a/static/skin/i18n/en.json +++ b/static/skin/i18n/en.json @@ -20,6 +20,8 @@ , "400-page-heading" : "Invalid request" , "404-page-title" : "Content not found" , "404-page-heading" : "Not Found" + , "new-404-page-title" : "Page not found" + , "new-404-page-heading" : "Oops. Page not found." , "500-page-title" : "Internal Server Error" , "500-page-heading" : "Internal Server Error" , "500-page-text": "An internal server error occured. We are sorry about that :/" diff --git a/static/skin/i18n/qqq.json b/static/skin/i18n/qqq.json index 6ddc1453..a1699b35 100644 --- a/static/skin/i18n/qqq.json +++ b/static/skin/i18n/qqq.json @@ -24,6 +24,8 @@ "400-page-heading": "Heading of the 400 error page", "404-page-title": "Title of the 404 error page", "404-page-heading": "Heading of the 404 error page", + "new-404-page-title": "Title of the 404 error page", + "new-404-page-heading": "Heading of the 404 error page", "500-page-title": "Title of the 500 error page", "500-page-heading": "Heading of the 500 error page", "500-page-text": "Text of the 500 error page", diff --git a/static/skin/i18n/test.json b/static/skin/i18n/test.json index bdde1272..3000ca0c 100644 --- a/static/skin/i18n/test.json +++ b/static/skin/i18n/test.json @@ -13,6 +13,8 @@ , "400-page-heading": "[I18N TESTING] -400 karma for an invalid request" , "404-page-title": "[I18N TESTING] Not Found - Try Again" , "404-page-heading": "[I18N TESTING] Content not found, but at least the server is alive" + , "new-404-page-title" : "Page [I18N] not [TESTING] found" + , "new-404-page-heading" : "[I18N TESTING] Oops. Larry Page could not be reached. He may be on paternity leave." , "library-button-text": "[I18N TESTING] Navigate to the welcome page" , "home-button-text": "[I18N TESTING] Jump to the main page of '{{BOOK_TITLE}}'" , "random-page-button-text": "[I18N TESTING] I am tired of determinism" diff --git a/static/templates/sexy404.html b/static/templates/sexy404.html index 17be51ec..5f60f5ac 100644 --- a/static/templates/sexy404.html +++ b/static/templates/sexy404.html @@ -3,8 +3,12 @@ - Page not found + {{PAGE_TITLE}} +{{#KIWIX_RESPONSE_DATA}} {{/KIWIX_RESPONSE_DATA}}
@@ -14,7 +18,7 @@ title="Not found!">
-

Oops. Page not found.

+

{{PAGE_HEADING}}

The requested path was not found:

{{url_path}}

diff --git a/test/server.cpp b/test/server.cpp index 97bb2b5a..07e25597 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -346,6 +346,7 @@ R"EXPECTEDRESULT( + window.KIWIX_RESPONSE_TEMPLATE = "<!DOCTYPE html>\n<html>\n <head>\n <meta charset="utf-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />\n <title>{{PAGE_TITLE}}</title>\n <link type="text/css" href="{{root}}/skin/error.css?cacheid=c49d1586" rel="Stylesheet" />\n{{#KIWIX_RESPONSE_DATA}} <script>\n window.KIWIX_RESPONSE_TEMPLATE = "{{KIWIX_RESPONSE_TEMPLATE}}";\n window.KIWIX_RESPONSE_DATA = {{{KIWIX_RESPONSE_DATA}}};\n </script>{{/KIWIX_RESPONSE_DATA}}\n </head>\n <body>\n <header>\n <img src="{{root}}/skin/404.svg?cacheid=b6d648af"\n alt="Not found!"\n aria-label="Not found!"\n title="Not found!">\n </header>\n <section class="intro">\n <h1>{{PAGE_HEADING}}</h1>\n <p>The requested path was not found:</p>\n <p><code>{{url_path}}</code></p>\n </section>\n <section class="advice">\n <p>The content you're looking for may still be available, but it might be located at a different place within the ZIM file.</p>\n <p class="list-intro">Please:</p>\n <ul>\n <li>Try using the search function to find the content you want</li>\n <li>Look for keywords or titles related to the information you're seeking</li>\n </ul>\n <p>This approach should help you locate the desired content, even if the original link isn't working properly.</p>\n </section>\n </body>\n</html>\n"; ", ""); + s = replace(s, "\"", "\\\""); + return s; +} + std::string expectedSexy404ErrorHtml(const std::string& url) { const auto htmlSafeUrl = htmlEscape(url); + const auto jsSafeUrl = escapeJsString(url); return R"RAWSTRINGLITERAL( @@ -933,6 +942,14 @@ std::string expectedSexy404ErrorHtml(const std::string& url) Page not found +
@@ -1458,37 +1475,37 @@ TEST_F(ServerTest, UserLanguageControl) "Default user language is English", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article", /*Accept-Language:*/ "", - /* expected

*/ "Not Found" + /* expected

*/ "Oops. Page not found." }, { "userlang URL query parameter is respected", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=en", /*Accept-Language:*/ "", - /* expected

*/ "Not Found" + /* expected

*/ "Oops. Page not found." }, { "userlang URL query parameter is respected", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=test", /*Accept-Language:*/ "", - /* expected

*/ "[I18N TESTING] Content not found, but at least the server is alive" + /* expected

*/ "[I18N TESTING] Oops. Larry Page could not be reached. He may be on paternity leave." }, { "'Accept-Language: *' is handled", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article", /*Accept-Language:*/ "*", - /* expected

*/ "Not Found" + /* expected

*/ "Oops. Page not found." }, { "Accept-Language: header is respected", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article", /*Accept-Language:*/ "test", - /* expected

*/ "[I18N TESTING] Content not found, but at least the server is alive" + /* expected

*/ "[I18N TESTING] Oops. Larry Page could not be reached. He may be on paternity leave." }, { "userlang query parameter takes precedence over Accept-Language", /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article?userlang=en", /*Accept-Language:*/ "test", - /* expected

*/ "Not Found" + /* expected

*/ "Oops. Page not found." }, { "Most suitable language is selected from the Accept-Language header", @@ -1496,7 +1513,7 @@ TEST_F(ServerTest, UserLanguageControl) // with quality values) the most suitable language is selected. /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article", /*Accept-Language:*/ "test;q=0.9, en;q=0.2", - /* expected

*/ "[I18N TESTING] Content not found, but at least the server is alive" + /* expected

*/ "[I18N TESTING] Oops. Larry Page could not be reached. He may be on paternity leave." }, { "Most suitable language is selected from the Accept-Language header", @@ -1504,7 +1521,7 @@ TEST_F(ServerTest, UserLanguageControl) // with quality values) the most suitable language is selected. /*url*/ "/ROOT%23%3F/content/zimfile/invalid-article", /*Accept-Language:*/ "test;q=0.2, en;q=0.9", - /* expected

*/ "Not Found" + /* expected

*/ "Oops. Page not found." }, };