From 7bf25f232569aa62edf1c88e7014a9f3c1b37014 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Thu, 20 Jul 2017 18:08:12 +0200 Subject: feat: Create feed handler for root --- src/app.js | 13 +++++++++++++ src/domain/posts.js | 2 ++ src/responders.js | 42 ++++++++++++++++++++++++++++++++++++++++-- src/templates/feed.xml | 24 ++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/templates/feed.xml (limited to 'src') diff --git a/src/app.js b/src/app.js index 912dda2..a323b9c 100644 --- a/src/app.js +++ b/src/app.js @@ -13,6 +13,13 @@ const config = require("./modules/config.js"); const Router = require("koa-router"); const router = new Router(); +const makeTagURI = (authority, startDate) => specific => + `tag:${authority},${startDate}:${specific}`; + +app.context.makeTagURI = makeTagURI( + config.feed.originalDomainName, + config.feed.domainStartDate +); app.context.getURL = router.url.bind(router); module.exports = async function() { @@ -34,6 +41,12 @@ module.exports = async function() { actions.highlightTheme(config) ); + router.get( + "feed", + "/index.xml", + actions.posts(config, responders.feed, Posts.posts) + ); + router.get( "post", "/post/:filename", diff --git a/src/domain/posts.js b/src/domain/posts.js index 98488ba..ab35518 100644 --- a/src/domain/posts.js +++ b/src/domain/posts.js @@ -86,7 +86,9 @@ function taxonomise(taxonomies, posts) { module.exports = async function(config, getURL) { const posts = await getFolder(config.folder, getURL); const taxonomies = taxonomise(config.taxonomies, posts); + const lastPostDate = Math.max(Array.from(posts.values(), p => p.date)); return { + lastPostDate, posts, taxonomies, get diff --git a/src/responders.js b/src/responders.js index 8f084a3..f4ea0a6 100644 --- a/src/responders.js +++ b/src/responders.js @@ -1,6 +1,7 @@ "use strict"; const fs = require("fs"); +const URL = require("url").URL; const Case = require("case"); const hyperfast = require("hyperfast"); const indent = require("indent-string"); @@ -25,7 +26,7 @@ const findPostContent = /^(\s+)
This is the entry content.
+