-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevlog.js
34 lines (28 loc) · 908 Bytes
/
devlog.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
const fetch = require('node-fetch');
const fs = require('fs');
const moment = require('moment');
const xml2js = require('xml2js');
async function get () {
const res = await fetch('https://coupling.substack.com/feed.xml');
const text = await res.text();
const data = await new Promise(resolve => {
xml2js.parseString(text, (err, result) => {
resolve(result);
});
});
const out = data.rss.channel[0].item.map(blog => {
blog.title = blog.title[0];
if (blog.title.indexOf(':') !== -1) {
blog.title = blog.title.split(':')[1];
}
blog.date = moment(blog.pubDate[0]).format('MMMM DD YYYY');
try {
blog.image = blog.description[0].match(new RegExp('(https.*?)"'))[1];
} catch (e) {
blog.image = '/assets/img/logo.png';
}
return blog;
});
fs.writeFileSync('./src/_data/blog.json', JSON.stringify(data.rss.channel[0].item));
}
get();