Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OPDS/Atom Feed link in HTML head #882

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions static/resources_list.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
skin/caret.png
skin/bittorrent.png
skin/magnet.png
skin/feed.png
skin/download.png
skin/hash.png
skin/search-icon.svg
Expand Down
Binary file added static/skin/feed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions static/skin/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ body {
width: auto;
}

.feedLogo {
margin: 16px 12px 0 0;
height: 30px;
float: right;
border-radius: 5px;
}

@media screen and (max-width: 1100px) {

.kiwixHomeBody {
Expand Down Expand Up @@ -482,4 +489,8 @@ body {
.kiwixNav__filters {
grid-template-columns: 1fr;
}

.feedLogo {
display: none;
}
}
15 changes: 15 additions & 0 deletions static/skin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
let timer;
let languages = {};

function updateFeedLink() {
const inputParams = new URLSearchParams(window.location.search);
const filteredParams = new URLSearchParams();
for (const [key, value] of inputParams) {
if ( value != '' ) {
filteredParams.append(key, value);
}
}
const feedLink = `${root}/catalog/v2/entries?${filteredParams.toString()}`;
document.querySelector('#headFeedLink').href = feedLink;
document.querySelector('#feedLink').href = feedLink;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see in the current naming of the OPDS feed link ids a risk that any future links will be named feedlink, FeedLink, etc :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was worried about it too :P but kelson's recommendation so I let it pass.
What do you think is a better name?
@kelson42 @veloman-yunkan

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep only version of feedLink or feed_link to have the naming consistant.
But we should have a id for the link in the head as head_feed_link (or headFeedLink) and feed_link (or FeedLink).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headFeedLink then :)


function queryUrlBuilder() {
let url = `${root}/catalog/search?`;
url += Object.keys(incrementalLoadingParams).map(key => `${key}=${incrementalLoadingParams[key]}`).join("&");
Expand Down Expand Up @@ -363,6 +376,7 @@
setCookie(filterCookieName, params.toString());
}
updateFilterColors();
updateFeedLink();
await loadAndDisplayBooks(true);
}

Expand Down Expand Up @@ -492,6 +506,7 @@
langFilter.dispatchEvent(new Event('change'));
}
}
updateFeedLink();
setCookie(filterCookieName, params.toString());
}
})();
Expand Down
10 changes: 10 additions & 0 deletions static/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
href="{{root}}/skin/index.css?KIWIXCACHEID"
rel="Stylesheet"
/>
<link
juuz0 marked this conversation as resolved.
Show resolved Hide resolved
rel="alternate"
type="application/atom+xml"
title="Library OPDS Feed"
id="headFeedLink"
href="{{root}}/catalog/v2/entries"
/>
<link rel="apple-touch-icon" sizes="180x180" href="{{root}}/skin/favicon/apple-touch-icon.png?KIWIXCACHEID">
<link rel="icon" type="image/png" sizes="32x32" href="{{root}}/skin/favicon/favicon-32x32.png?KIWIXCACHEID">
<link rel="icon" type="image/png" sizes="16x16" href="{{root}}/skin/favicon/favicon-16x16.png?KIWIXCACHEID">
Expand All @@ -35,6 +42,9 @@
<script type="text/javascript" src="{{root}}/skin/index.js?KIWIXCACHEID" defer></script>
</head>
<body>
<a href="{{root}}/catalog/v2/entries" id="feedLink">
<img src="{{root}}/skin/feed.png?KIWIXCACHEID" class="feedLogo" alt="Library OPDS Feed" aria-label="Library OPDS Feed" title="Library OPDS Feed">
</a>
<div class='kiwixNav'>
<div class="kiwixNav__filters">
<div class="kiwixNav__select">
Expand Down
9 changes: 5 additions & 4 deletions test/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ const ResourceCollection resources200Compressible{
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/i18n.js" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/i18n.js?cacheid=6da2bca0" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.css" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/index.css?cacheid=0f9ba34e" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/index.css?cacheid=316dbc21" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.js" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/index.js?cacheid=2f5a81ac" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/index.js?cacheid=b0cc9d6b" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/isotope.pkgd.min.js" },
Expand Down Expand Up @@ -268,7 +268,7 @@ TEST_F(ServerTest, CacheIdsOfStaticResources)
const std::vector<UrlAndExpectedResult> testData{
{
/* url */ "/ROOT%23%3F/",
R"EXPECTEDRESULT( href="/ROOT%23%3F/skin/index.css?cacheid=0f9ba34e"
R"EXPECTEDRESULT( href="/ROOT%23%3F/skin/index.css?cacheid=316dbc21"
<link rel="apple-touch-icon" sizes="180x180" href="/ROOT%23%3F/skin/favicon/apple-touch-icon.png?cacheid=f86f8df3">
<link rel="icon" type="image/png" sizes="32x32" href="/ROOT%23%3F/skin/favicon/favicon-32x32.png?cacheid=79ded625">
<link rel="icon" type="image/png" sizes="16x16" href="/ROOT%23%3F/skin/favicon/favicon-16x16.png?cacheid=a986fedc">
Expand All @@ -280,7 +280,8 @@ R"EXPECTEDRESULT( href="/ROOT%23%3F/skin/index.css?cacheid=0f9ba34e"
src: url("/ROOT%23%3F/skin/fonts/Roboto.ttf?cacheid=84d10248") format("truetype");
<script src="/ROOT%23%3F/skin/isotope.pkgd.min.js?cacheid=2e48d392" defer></script>
<script src="/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3"></script>
<script type="text/javascript" src="/ROOT%23%3F/skin/index.js?cacheid=2f5a81ac" defer></script>
<script type="text/javascript" src="/ROOT%23%3F/skin/index.js?cacheid=b0cc9d6b" defer></script>
<img src="/ROOT%23%3F/skin/feed.png?cacheid=56a672b1" class="feedLogo" alt="Library OPDS Feed" aria-label="Library OPDS Feed" title="Library OPDS Feed">
)EXPECTEDRESULT"
},
{
Expand Down