This repository has been archived by the owner on Nov 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rssBuild.js
82 lines (75 loc) · 1.99 KB
/
rssBuild.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const Podcast = require('podcast');
const fs = require('fs');
const yaml = require('js-yaml');
let config
let episode
try {
episode = yaml.safeLoad(fs.readFileSync('./src/assets/episode.yml', 'utf8'));
config = yaml.safeLoad(fs.readFileSync('./src/assets/config.yml', 'utf8'));
} catch (e) {
console.log(e);
}
const {episodeList} = episode
const {domain, author} = config
/* lets create an rss feed */
const feed = new Podcast({
title: 'FAcast',
description: 'FAcast',
feed_url: `${domain}/feed.xml`,
site_url: `${domain}`,
image_url: `${domain}/static/ogp.png`,
docs: '雑談系Podcast',
author: author,
managingEditor: author,
webMaster: author,
copyright: '2018 Okada Genya',
language: 'ja',
categories: ['car', 'auto', 'frontend'],
pubDate: episodeList[0].pubDate,
ttl: '60',
itunesAuthor: author,
itunesSubtitle: '雑談系Podcast',
itunesSummary: '雑談系Podcast',
itunesOwner: { name: 'Okada Genya', email:'[email protected]' },
itunesExplicit: false,
itunesCategory: [{
"text": "Technology",
"subcats": [{
"text": "Technology"
}]
}],
itunesImage: `${domain}/static/ogp.png` // 1400? http://cdn.rebuild.fm/images/icon1400.j`
});
/* loop over data and add to feed */
const feedConst = {
itunesAuthor: author,
itunesExplicit: false
}
episodeList.reverse().forEach(({
title,
description,
pubDate,
duration,
uid
}) => {
const path = `/static/storage/${uid}.mp3`;
const stat = fs.statSync(`.${path}`);
feed.addItem(Object.assign({}, {
title: `${uid} ${title}`,
description,
url: `${domain}/${uid}`, // link to the item
date: pubDate, // any format that js Date can parse.
itunesDuration: duration,
enclosure: {
url: `${domain}${path}`,
type: 'audio/mpeg',
length: `${stat.size}`
}
}, feedConst));
});
// cache the xml to send to clients
const xml = feed.buildXml();
fs.writeFile('dist/feed.xml', xml, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});