-
Notifications
You must be signed in to change notification settings - Fork 4
/
build-feed.js
49 lines (43 loc) · 1011 Bytes
/
build-feed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict'
const unified = require('unified')
const markdown = require('remark-parse')
const remark2rehype = require('remark-rehype')
const html = require('rehype-stringify')
const RssFeed = require('rss')
const pkg = require('./package.json')
const feedItems = require('./feed')
const pipeline = unified()
.use(markdown)
.use(remark2rehype)
.use(html)
const md = (md) => {
return new Promise((resolve, reject) => {
pipeline.process(md, (err, file) => {
if (err) reject(err)
else resolve(file.contents)
})
})
}
;(async () => {
const feed = new RssFeed({
title: pkg.name + ' news',
description: pkg.description,
feed_url: pkg.homepage + 'news.xml',
site_url: pkg.homepage,
ttl: 60
})
for (let item of feedItems) {
feed.item({
title: item.title,
description: await md(item.body, {enableHeadingLinkIcons: false}),
url: item.url,
guid: item.id,
date: item.date
})
}
process.stdout.write(feed.xml())
})()
.catch((err) => {
console.error(err)
process.exit(1)
})