X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/67fdfa7cc2e1690657cd0c7190373847de25311a..e8a4197dcaf454b4dbe76d5ddd84f63fa5693ab9:/lib/generators/rss.js?ds=sidebyside diff --git a/lib/generators/rss.js b/lib/generators/rss.js index a1fcb08..4ae3925 100644 --- a/lib/generators/rss.js +++ b/lib/generators/rss.js @@ -1,6 +1,6 @@ 'use strict'; -const { template } = require('dot'); +const { template, templateSettings } = require('dot'); const { encodeXML } = require('entities'); const { readFile, writeFile } = require('fs/promises'); const { join } = require('path'); @@ -9,7 +9,16 @@ const { debuglog } = require('util'); const internals = { debuglog: debuglog('blog'), - kFeedName: 'feed.xml' + kFeedName: 'feed.xml', + + extractTitle(postText) { + + return postText.trim() + .split('\n')[0] + .replace('#', '') + .replace(/&/g, '&') + .trim(); + } }; /** @@ -33,10 +42,12 @@ module.exports = async function RSSGenerator(source, target, posts) { posts = posts.map((post) => ({ ...post, createdOn: (new Date(post.createdOn)).toUTCString(), + title: internals.extractTitle(post.raw), html: encodeXML(post.html) })); - const feedXml = template(feedTemplate)({ posts }); + const feedXml = template(feedTemplate, { + ...templateSettings, + strip: false + })({ posts }); await writeFile(feedTarget, feedXml); }; - -