'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');
const internals = {
debuglog: debuglog('blog'),
- kFeedName: 'feed.xml'
+ kFeedName: 'feed.xml',
+
+ extractTitle(postText) {
+
+ return postText.trim()
+ .split('\n')[0]
+ .replace('#', '')
+ .replace(/&/g, '&')
+ .trim();
+ }
};
/**
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);
};
-
-