From 2be9ac342ffd31a23561b794bfe47ce08f8e1694 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 10 Jul 2022 15:56:41 +0400 Subject: [PATCH] Partly respecting the kiwix-serve --nosearchbar option `--nosearchbar` option of `kiwix-serve` (despite its misleading name) was used to disable the entire taskbar. This commit accounts for the existence of that option only partially: 1. Links to books on the welcome/library page are affected - by default books are displayed in the viewer, but in a kiwix-serve instance run with --nosearchbar books are loaded in the top window. 2. The `/viewer` endpoint is enabled unconditionally, so if anyone enters the viewer URL in the address bar they will see books in the viewer. --- src/server/internalServer.cpp | 4 +++- static/skin/index.js | 4 +++- static/templates/index.html | 1 + test/server.cpp | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index b1bb904e2..07bc77791 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -626,7 +626,9 @@ InternalServer::get_matching_if_none_match_etag(const RequestContext& r) const std::unique_ptr InternalServer::build_homepage(const RequestContext& request) { - return ContentResponse::build(*this, m_indexTemplateString, get_default_data(), "text/html; charset=utf-8"); + auto data = get_default_data(); + data.set("enable_viewer", m_withTaskbar ? "true" : "false"); + return ContentResponse::build(*this, m_indexTemplateString, data, "text/html; charset=utf-8"); } /** diff --git a/static/skin/index.js b/static/skin/index.js index 7f29b316e..6bf46db68 100644 --- a/static/skin/index.js +++ b/static/skin/index.js @@ -111,7 +111,9 @@ downloadLink = ''; } const bookName = link.split('/').pop(); - const viewerLink = `${root}/viewer#${bookName}`; + const viewerLink = enableViewer + ? `${root}/viewer#${bookName}` + : link; const humanFriendlyZimSize = humanFriendlySize(zimSize); diff --git a/static/templates/index.html b/static/templates/index.html index 42bbc6a1b..61fd9f841 100644 --- a/static/templates/index.html +++ b/static/templates/index.html @@ -32,6 +32,7 @@ + diff --git a/test/server.cpp b/test/server.cpp index d76b9c403..42290245e 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -184,7 +184,7 @@ R"EXPECTEDRESULT( href="/ROOT/skin/index.css?cacheid=3b470cee" src: url("/ROOT/skin/fonts/Roboto.ttf?cacheid=84d10248") format("truetype"); - + )EXPECTEDRESULT" }, {