Dropped root link injection

The only place that the root link is now used is in /skin/index.js,
so added it in static/templates/index.html. But it seems that nothing
prevents us from from switching from aboslute paths to relative paths
in /skin/index.js, which will eliminate the need for the root link
altogether.

As a result of this change content is never decorated by kiwix serve.
This commit is contained in:
Veloman Yunkan 2022-06-29 11:53:43 +04:00
parent 685e7f8ad4
commit a674561110
5 changed files with 5 additions and 15 deletions

View File

@ -321,13 +321,6 @@ void print_response_info(int retCode, MHD_Response* response)
} }
void ContentResponse::inject_root_link(){
m_content = prependToFirstOccurence(
m_content,
"</head[ \\t]*>",
"<link type=\"root\" href=\"" + m_root + "\">");
}
bool bool
ContentResponse::can_compress(const RequestContext& request) const ContentResponse::can_compress(const RequestContext& request) const
{ {
@ -356,10 +349,6 @@ Response::create_mhd_response(const RequestContext& request)
MHD_Response* MHD_Response*
ContentResponse::create_mhd_response(const RequestContext& request) ContentResponse::create_mhd_response(const RequestContext& request)
{ {
if (contentDecorationAllowed()) {
inject_root_link();
}
const bool isCompressed = can_compress(request) && compress(m_content); const bool isCompressed = can_compress(request) && compress(m_content);
MHD_Response* response = MHD_create_response_from_buffer( MHD_Response* response = MHD_create_response_from_buffer(

View File

@ -103,7 +103,6 @@ class ContentResponse : public Response {
private: private:
MHD_Response* create_mhd_response(const RequestContext& request); MHD_Response* create_mhd_response(const RequestContext& request);
void inject_root_link();
bool can_compress(const RequestContext& request) const; bool can_compress(const RequestContext& request) const;
bool contentDecorationAllowed() const; bool contentDecorationAllowed() const;

View File

@ -3,6 +3,7 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" /> <meta name="viewport" content="width=device-width,initial-scale=1" />
<link type="root" href="{{root}}">
<title>Welcome to Kiwix Server</title> <title>Welcome to Kiwix Server</title>
<link <link
type="text/css" type="text/css"

View File

@ -121,7 +121,6 @@ TEST(indexTemplateStringTest, indexTemplateCheck) {
"</html>"); "</html>");
EXPECT_EQ("<!DOCTYPE html><head>" EXPECT_EQ("<!DOCTYPE html><head>"
"<title>Welcome to kiwix library</title>" "<title>Welcome to kiwix library</title>"
"<link type=\"root\" href=\"/ROOT\">"
"</head>" "</head>"
"</html>", zfs.GET("/ROOT/")->body); "</html>", zfs.GET("/ROOT/")->body);
} }
@ -447,7 +446,7 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const
)FRAG", )FRAG",
R"FRAG( R"FRAG(
<link type="root" href="/ROOT"></head> </head>
<body>)FRAG", <body>)FRAG",
R"FRAG( </body> R"FRAG( </body>
@ -1028,11 +1027,13 @@ TEST_F(ServerTest, RawEntry)
EXPECT_EQ(200, p->status); EXPECT_EQ(200, p->status);
EXPECT_EQ(std::string(p->body), std::string(entry.getItem(true).getData())); EXPECT_EQ(std::string(p->body), std::string(entry.getItem(true).getData()));
/* Now normal content is not decorated in any way, either
// ... but the "normal" content is not // ... but the "normal" content is not
p = zfs1_->GET("/ROOT/content/zimfile/A/Ray_Charles"); p = zfs1_->GET("/ROOT/content/zimfile/A/Ray_Charles");
EXPECT_EQ(200, p->status); EXPECT_EQ(200, p->status);
EXPECT_NE(std::string(p->body), std::string(entry.getItem(true).getData())); EXPECT_NE(std::string(p->body), std::string(entry.getItem(true).getData()));
EXPECT_TRUE(p->body.find("<link type=\"root\" href=\"/ROOT\">") != std::string::npos); EXPECT_TRUE(p->body.find("<link type=\"root\" href=\"/ROOT\">") != std::string::npos);
*/
} }
TEST_F(ServerTest, HeadMethodIsSupported) TEST_F(ServerTest, HeadMethodIsSupported)

View File

@ -112,7 +112,7 @@ std::string makeSearchResultsHtml(const std::string& pattern,
</style> </style>
<title>Search: %PATTERN%</title> <title>Search: %PATTERN%</title>
<link type="root" href="/ROOT"></head> </head>
<body bgcolor="white"> <body bgcolor="white">
<div class="header"> <div class="header">
%HEADER% %HEADER%