diff --git a/index.js b/index.js index ff2417f..ae7a392 100644 --- a/index.js +++ b/index.js @@ -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, }) diff --git a/templates/list_posts.handlebars b/templates/list_posts.handlebars index 29eda2a..f80d1ca 100644 --- a/templates/list_posts.handlebars +++ b/templates/list_posts.handlebars @@ -8,8 +8,12 @@ {{page_title}} + - + + @@ -17,14 +21,25 @@
{{page_title}}
+
{{#each items}}
@@ -47,11 +62,29 @@

- All rights belong to the original authors. - Back to top + All rights belong to the original authors. + Back to top

+
+
+

About

+ +
+
+

{{page_description}}

+ +
Sources
+
    + {{#each sources}} +
  • {{name}}
  • + {{/each}} +
+
+
+ diff --git a/templates/list_posts.precompiled.js b/templates/list_posts.precompiled.js index d1281aa..e2820e5 100644 --- a/templates/list_posts.precompiled.js +++ b/templates/list_posts.precompiled.js @@ -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
\n \n \n \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 ( + '
  • ' + + 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), + ) + + '
  • \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 \n \n\n\n\n \n\n
    \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 : '') + - '
    \n \n\n\n\n' + '
    \n \n
    \n
    \n

    About

    \n \n
    \n
    \n

    ' + + 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), + ) + + '

    \n\n
    Sources
    \n \n
    \n
    \n \n\n\n\n' ) }, useData: true,