Add about panel

This commit is contained in:
Gonçalo Valério 2021-05-30 22:14:13 +01:00
parent 6c3f850cf0
commit 6ee46c97fd
Signed by: dethos
GPG Key ID: DF557F2BDCC2445E
3 changed files with 163 additions and 27 deletions

View File

@ -31,8 +31,6 @@ async function handleRequest(request) {
headers: {
'content-type': 'text/html;charset=UTF-8',
'Cache-Control': `max-age=${cacheMaxAge}`,
'Content-Security-Policy':
"script-src 'none'; style-src cdn.jsdelivr.net;",
},
})
} else if (path === '/rss') {
@ -63,10 +61,12 @@ async function handleRequest(request) {
async function handleScheduled(event) {
let feeds = FEEDS.split(',')
let content = []
let sources = []
let items
for (let url of feeds) {
try {
items = await fetchAndHydrate(url)
sources.push({ name: items[0].source_title, link: items[0].source_link })
} catch (error) {
console.log(`Failed to fetch ${url}`)
console.log(error)
@ -93,7 +93,7 @@ async function handleScheduled(event) {
// Generate feed
let feed = createFeed(content)
let html = createHTML(content)
let html = createHTML(content, sources)
// Store
await WORKER_PLANET_STORE.put('rss', feed.rss2())
//await WORKER_PLANET_STORE.put('atom', feed.atom1())
@ -127,6 +127,7 @@ async function fetchAndHydrate(feed) {
* @param {Array} items
*/
function createFeed(items) {
console.log(`[createFeed] start building the aggregated feed`)
const feed = new Feed({
title: TITLE,
description: DESCRIPTION,
@ -152,6 +153,7 @@ function createFeed(items) {
date: new Date(item.isoDate),
})
}
console.log(`[createFeed] Finished building the aggregated feed`)
return feed
}
/**
@ -159,10 +161,12 @@ function createFeed(items) {
* @param {*} items
* @returns
*/
function createHTML(items) {
function createHTML(items, sources) {
console.log(`[createHTML] building the HTML document`)
let template = Handlebars.templates['list_posts']
return template({
items: items,
sources: sources,
page_title: TITLE,
page_description: DESCRIPTION,
})

View File

@ -8,8 +8,12 @@
<title>{{page_title}}</title>
<meta property="og:title" content="{{page_title}}" />
<meta property="og:description" content="{{page_description}}" />
<meta http-equiv="Content-Security-Policy" content="script-src https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js; style-src https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css;">
<link rel="alternate" type="application/rss+xml" title="Planet RSS feed" href="/rss" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css"
integrity="sha256-PDJQdTN7dolQWDASIoBVrjkuOEaI137FI15sqI3Oxu8=" crossorigin="anonymous" />
</head>
<body>
@ -17,14 +21,25 @@
<div class="container-fluid">
<a class="navbar-brand" href="#">{{page_title}}</a>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/rss">
<i class="bi bi-rss" role="img" aria-label="RSS"></i> RSS Feed
</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="https://github.com/dethos/worker-planet">
Source Code
<i class="bi bi-github" role="img" aria-label="GitHub"></i> Source Code
</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" data-bs-toggle="offcanvas" data-bs-target="#aboutPanel" aria-controls="offcanvasRight" href="#">
<i class="bi bi-patch-question" role="img" aria-label="About"></i> About
</a>
</li>
</ul>
</div>
</nav>
<main class="container d-grid">
{{#each items}}
<div class="row p-2">
@ -47,11 +62,29 @@
<footer class="footer mt-auto py-3 bg-light">
<div class="container-fluid">
<p class="text-muted">
All rights belong to the original authors.
<a class="float-end" href="#">Back to top</a>
<span>All rights belong to the original authors.</span>
<span class="float-end"><a href="#">Back to top</a></span>
</p>
</div>
</footer>
<div class="offcanvas offcanvas-end" tabindex="-1" id="aboutPanel" aria-labelledby="aboutLabel">
<div class="offcanvas-header">
<h4 id="aboutLabel">About</h4>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<p>{{page_description}}</p>
<h5>Sources</h5>
<ul>
{{#each sources}}
<li><a href="{{link}}">{{name}}</a></li>
{{/each}}
</ul>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
</body>
</html>

View File

@ -33,8 +33,8 @@ templates['list_posts'] = template({
hash: {},
data: data,
loc: {
start: { line: 34, column: 44 },
end: { line: 34, column: 52 },
start: { line: 49, column: 44 },
end: { line: 49, column: 52 },
},
})
: helper),
@ -53,8 +53,8 @@ templates['list_posts'] = template({
hash: {},
data: data,
loc: {
start: { line: 34, column: 54 },
end: { line: 34, column: 63 },
start: { line: 49, column: 54 },
end: { line: 49, column: 63 },
},
})
: helper),
@ -74,8 +74,8 @@ templates['list_posts'] = template({
hash: {},
data: data,
loc: {
start: { line: 36, column: 27 },
end: { line: 36, column: 38 },
start: { line: 51, column: 27 },
end: { line: 51, column: 38 },
},
})
: helper),
@ -96,8 +96,8 @@ templates['list_posts'] = template({
hash: {},
data: data,
loc: {
start: { line: 37, column: 38 },
end: { line: 37, column: 53 },
start: { line: 52, column: 38 },
end: { line: 52, column: 53 },
},
})
: helper),
@ -118,8 +118,8 @@ templates['list_posts'] = template({
hash: {},
data: data,
loc: {
start: { line: 37, column: 55 },
end: { line: 37, column: 71 },
start: { line: 52, column: 55 },
end: { line: 52, column: 71 },
},
})
: helper),
@ -139,8 +139,8 @@ templates['list_posts'] = template({
hash: {},
data: data,
loc: {
start: { line: 40, column: 12 },
end: { line: 40, column: 25 },
start: { line: 55, column: 12 },
end: { line: 55, column: 25 },
},
})
: helper)) != null
@ -149,6 +149,65 @@ templates['list_posts'] = template({
'\n </div>\n </div>\n </article>\n </div>\n'
)
},
'3': function(container, depth0, helpers, partials, data) {
var helper,
alias1 = depth0 != null ? depth0 : container.nullContext || {},
alias2 = container.hooks.helperMissing,
alias3 = 'function',
alias4 = container.escapeExpression,
lookupProperty =
container.lookupProperty ||
function(parent, propertyName) {
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
return parent[propertyName]
}
return undefined
}
return (
' <li><a href="' +
alias4(
((helper =
(helper =
lookupProperty(helpers, 'link') ||
(depth0 != null ? lookupProperty(depth0, 'link') : depth0)) != null
? helper
: alias2),
typeof helper === alias3
? helper.call(alias1, {
name: 'link',
hash: {},
data: data,
loc: {
start: { line: 81, column: 23 },
end: { line: 81, column: 31 },
},
})
: helper),
) +
'">' +
alias4(
((helper =
(helper =
lookupProperty(helpers, 'name') ||
(depth0 != null ? lookupProperty(depth0, 'name') : depth0)) != null
? helper
: alias2),
typeof helper === alias3
? helper.call(alias1, {
name: 'name',
hash: {},
data: data,
loc: {
start: { line: 81, column: 33 },
end: { line: 81, column: 41 },
},
})
: helper),
) +
'</a></li>\n'
)
},
compiler: [8, '>= 4.3.0'],
main: function(container, depth0, helpers, partials, data) {
var stack1,
@ -231,7 +290,7 @@ templates['list_posts'] = template({
})
: helper),
) +
'" />\n <link rel="alternate" type="application/rss+xml" title="Planet RSS feed" href="/rss" />\n <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">\n</head>\n\n<body>\n <nav class="navbar navbar-expand-lg navbar-light bg-light">\n <div class="container-fluid">\n <a class="navbar-brand" href="#">' +
'" />\n <meta http-equiv="Content-Security-Policy" content="script-src https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js; style-src https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css;">\n <link rel="alternate" type="application/rss+xml" title="Planet RSS feed" href="/rss" />\n <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"\n integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous" />\n <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css"\n integrity="sha256-PDJQdTN7dolQWDASIoBVrjkuOEaI137FI15sqI3Oxu8=" crossorigin="anonymous" />\n</head>\n\n<body>\n <nav class="navbar navbar-expand-lg navbar-light bg-light">\n <div class="container-fluid">\n <a class="navbar-brand" href="#">' +
alias4(
((helper =
(helper =
@ -246,13 +305,13 @@ templates['list_posts'] = template({
hash: {},
data: data,
loc: {
start: { line: 18, column: 39 },
end: { line: 18, column: 53 },
start: { line: 22, column: 39 },
end: { line: 22, column: 53 },
},
})
: helper),
) +
'</a>\n <ul class="navbar-nav ms-auto">\n <li class="nav-item">\n <a class="nav-link active" aria-current="page" href="https://github.com/dethos/worker-planet">\n Source Code\n </a>\n </li>\n </ul>\n </div>\n </nav>\n <main class="container d-grid">\n' +
'</a>\n <ul class="navbar-nav ms-auto">\n <li class="nav-item">\n <a class="nav-link active" aria-current="page" href="/rss">\n <i class="bi bi-rss" role="img" aria-label="RSS"></i> RSS Feed\n </a>\n </li>\n <li class="nav-item">\n <a class="nav-link active" aria-current="page" href="https://github.com/dethos/worker-planet">\n <i class="bi bi-github" role="img" aria-label="GitHub"></i> Source Code\n </a>\n </li>\n <li class="nav-item">\n <a class="nav-link active" aria-current="page" data-bs-toggle="offcanvas" data-bs-target="#aboutPanel" aria-controls="offcanvasRight" href="#">\n <i class="bi bi-patch-question" role="img" aria-label="About"></i> About\n </a>\n </li>\n </ul>\n </div>\n </nav>\n\n <main class="container d-grid">\n' +
((stack1 = lookupProperty(helpers, 'each').call(
alias1,
depth0 != null ? lookupProperty(depth0, 'items') : depth0,
@ -263,14 +322,54 @@ templates['list_posts'] = template({
inverse: container.noop,
data: data,
loc: {
start: { line: 29, column: 4 },
end: { line: 45, column: 13 },
start: { line: 44, column: 4 },
end: { line: 60, column: 13 },
},
},
)) != null
? stack1
: '') +
' </main>\n <footer class="footer mt-auto py-3 bg-light">\n <div class="container-fluid">\n <p class="text-muted">\n All rights belong to the original authors.\n <a class="float-end" href="#">Back to top</a>\n </p>\n </div>\n </footer>\n</body>\n\n</html>\n'
' </main>\n <footer class="footer mt-auto py-3 bg-light">\n <div class="container-fluid">\n <p class="text-muted">\n <span>All rights belong to the original authors.</span>\n <span class="float-end"><a href="#">Back to top</a></span>\n </p>\n </div>\n </footer>\n <div class="offcanvas offcanvas-end" tabindex="-1" id="aboutPanel" aria-labelledby="aboutLabel">\n <div class="offcanvas-header">\n <h4 id="aboutLabel">About</h4>\n <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>\n </div>\n <div class="offcanvas-body">\n <p>' +
alias4(
((helper =
(helper =
lookupProperty(helpers, 'page_description') ||
(depth0 != null
? lookupProperty(depth0, 'page_description')
: depth0)) != null
? helper
: alias2),
typeof helper === alias3
? helper.call(alias1, {
name: 'page_description',
hash: {},
data: data,
loc: {
start: { line: 76, column: 9 },
end: { line: 76, column: 29 },
},
})
: helper),
) +
'</p>\n\n <h5>Sources</h5>\n <ul>\n' +
((stack1 = lookupProperty(helpers, 'each').call(
alias1,
depth0 != null ? lookupProperty(depth0, 'sources') : depth0,
{
name: 'each',
hash: {},
fn: container.program(3, data, 0),
inverse: container.noop,
data: data,
loc: {
start: { line: 80, column: 8 },
end: { line: 82, column: 17 },
},
},
)) != null
? stack1
: '') +
' </ul>\n </div>\n </div>\n <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"\n integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>\n</body>\n\n</html>\n'
)
},
useData: true,