-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss-truffle.js
53 lines (41 loc) · 1.16 KB
/
rss-truffle.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
50
51
52
// Was getting tired of trying to figure out how to write a Gatsby plugin, so here goes nothing
const jsonfile = require('jsonfile')
const RSS = require('rss')
const fs = require('fs')
var feed = jsonfile.readFileSync('static/feed.json')
var rss = new RSS({
title: "Joe's Truffles",
description: "An RSS representation of Joe's Truffle feed"
})
feed = feed.slice(0, 20)
feed.forEach(function(truffle) {
id = truffle.id
timestamp = truffle.timestamp
delete truffle.id
delete truffle.timestamp
var date = Date.parse(timestamp)
var content = ''
for (var field in truffle) {
content += '<p><strong>' + field + ':</strong> '
if(Array.isArray(truffle[field])) {
content += '<ul>'
truffle[field].forEach(function(arrayItem) {
content += '<li>' + arrayItem + '</li>'
})
content += '</ul>'
} else {
content += truffle[field]
}
content += '</p>'
}
rss.item({
url: 'https://truffle.jlleblanc.com/reader/#/' + id,
title: 'A truffle for ' + date,
date: timestamp,
description: content,
guid: id
})
})
var xml = rss.xml();
fs.writeFileSync('static/feed.xml', xml);
console.log(xml);