diff --git a/scripts/kiwix-resources b/scripts/kiwix-resources index 72e029a20..9c607dede 100755 --- a/scripts/kiwix-resources +++ b/scripts/kiwix-resources @@ -43,7 +43,7 @@ def fill_resource_revisions(resource_file_path): for resource in read_resource_file(resource_file_path): resource_revisions[resource] = get_resource_revision(base_dir, resource) -RESOURCE_WITH_CACHEID_URL_PATTERN=r'"([^"?]+)\?KIWIXCACHEID([^"]*)"' +RESOURCE_WITH_CACHEID_URL_PATTERN=r'([^"?]+)\?KIWIXCACHEID([^"]*)' def set_cacheid(resource_matchobj): path = resource_matchobj.group(1) @@ -53,7 +53,7 @@ def set_cacheid(resource_matchobj): resource = resource[len(root_prefix):] extra_query = resource_matchobj.group(2) cacheid = 'cacheid=' + resource_revisions[resource] - return f'"{path}?{cacheid}{extra_query}"' + return f'{path}?{cacheid}{extra_query}' def preprocess_line(line): if 'KIWIXCACHEID' in line: diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 748765615..95f999f99 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -442,6 +442,16 @@ SuggestionsList_t getSuggestions(SuggestionSearcherCache& cache, const zim::Arch namespace { +std::string renderUrl(const std::string& root, const std::string& urlTemplate) +{ + MustacheData data; + data.set("root", root); + auto url = kainjow::mustache::mustache(urlTemplate).render(data); + if ( url.back() == '\n' ) + url.pop_back(); + return url; +} + std::string makeFulltextSearchSuggestion(const std::string& lang, const std::string& queryString) { return i18n::expandParameterizedString(lang, "suggest-full-text-search", @@ -622,10 +632,11 @@ std::unique_ptr InternalServer::handle_search(const RequestContext& re } catch(std::runtime_error& e) { // Searcher->search will throw a runtime error if there is no valid xapian database to do the search. // (in case of zim file not containing a index) + const auto cssUrl = renderUrl(m_root, RESOURCE::templates::url_of_search_results_css); return HTTPErrorHtmlResponse(*this, request, MHD_HTTP_NOT_FOUND, "fulltext-search-unavailable", "404-page-heading", - m_root + "/skin/search_results.css") + cssUrl) + nonParameterizedMessage("no-search-results") + TaskbarInfo(searchInfo.bookName, archive.get()); } diff --git a/static/resources_list.txt b/static/resources_list.txt index 15275ad19..bc1eb1af3 100644 --- a/static/resources_list.txt +++ b/static/resources_list.txt @@ -47,5 +47,6 @@ templates/catalog_v2_entries.xml templates/catalog_v2_entry.xml templates/catalog_v2_categories.xml templates/catalog_v2_languages.xml +templates/url_of_search_results_css opensearchdescription.xml catalog_v2_searchdescription.xml diff --git a/static/templates/url_of_search_results_css b/static/templates/url_of_search_results_css new file mode 100644 index 000000000..f0ecb87d8 --- /dev/null +++ b/static/templates/url_of_search_results_css @@ -0,0 +1 @@ +{{root}}/skin/search_results.css?KIWIXCACHEID diff --git a/test/server.cpp b/test/server.cpp index 422cc2620..7a6ddf307 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -345,7 +345,7 @@ R"EXPECTEDRESULT( +R"EXPECTEDRESULT( @@ -847,7 +847,7 @@ TEST_F(ServerTest, 404WithBodyTesting) { /* url */ "/ROOT/search?content=poor&pattern=whatever", expected_page_title=="Fulltext search unavailable" && - expected_css_url=="/ROOT/skin/search_results.css" && + expected_css_url=="/ROOT/skin/search_results.css?cacheid=76d39c84" && book_name=="poor" && book_title=="poor" && expected_body==R"(