-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrss-gen.js
54 lines (50 loc) · 1.5 KB
/
rss-gen.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
/* eslint-disable import/extensions */
import fs from 'fs';
import Rss from 'rss';
import { getContent } from './utils/queries.js';
async function getRssData() {
const feed = new Rss({
title: 'Hanami Mastery newest episodes!',
description: 'The best way to master Hanami ruby framework!',
feed_url: 'https://hanamimastery.com/feed.xml',
author: 'Sebastian Wilgosz',
site_url: 'https://hanamimastery.com',
image_url: 'https://hanamimastery.com/logo-hm.jpeg',
managingEditor: 'Sebastian Wilgosz',
webMaster: 'Sebastian Wilgosz',
copyright: `${new Date().getFullYear()} Sebastian Wilgosz`,
language: 'en-us',
categories: ['Ruby', 'Hanami', 'Web development'],
pubDate: new Date().toUTCString(),
ttl: '60',
});
const posts = await getContent();
posts.map(({ excerpt, topics, publishedAt, fullTitle, url, thumbnail }) => {
const xmlItem = {
title: fullTitle,
image: thumbnail.big,
description: excerpt,
categories: topics,
date: publishedAt,
url,
};
// if (!!videoId) {
// xmlItem.enclosure = {
// 'url' : `https://www.youtube.com/embed/${videoId}`,
// 'type' : 'video'
// }
// }
return feed.item(xmlItem);
});
return feed;
}
async function generateRssFeed() {
try {
const feed = await getRssData();
fs.mkdirSync('./public/rss', { recursive: true });
fs.writeFileSync('./public/feed.xml', feed.xml());
} catch (error) {
console.log(error);
}
}
generateRssFeed();