-
Notifications
You must be signed in to change notification settings - Fork 7
/
build-rss-feed.js
61 lines (40 loc) · 2.05 KB
/
build-rss-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
50
51
52
53
54
55
56
57
58
59
60
61
const htmlParser = require('node-html-parser')
const fs = require('fs')
const RSS = require('rss-generator')
const fixSiteUrl = url => url.replace('../', 'https://www.orbs.com/')
async function generateRss() {
let blogsHtmlString = fs.readFileSync('./site/blog/index.html').toString()
let html = htmlParser.parse(blogsHtmlString)
let blogsHtml = html.querySelector('.blog-list').querySelectorAll('li.blog-list-blog.list-item.blog-element')
const feed = new RSS({
title: html.querySelector('#the-orbs-project-blog').childNodes[0]._rawText,
description: html.querySelector('#thoughts-about-the-orbs-project-open-source-blockchain-and-engineering-').childNodes[0]._rawText,
feed_url: 'https://www.orbs.com/blog/',
site_url: 'https://www.orbs.com/blog/',
image_url: 'https://www.orbs.com/assets/img/blog/first-orbs-rewards-distribution-summary/bg.jpg'
})
for (const blogHtml of blogsHtml) {
const titleNode = blogHtml.querySelector('.blog-list-blog-title').childNodes[0]
const author = blogHtml.querySelector('.blog-list-blog-author').querySelector('a')
if (titleNode && author) {
const imageUrl = blogHtml.attrs['data-image']
const link = blogHtml.querySelector('a').attrs['href']
const description = blogHtml.querySelector('.short-description-container').rawText
try {
const date = blogHtml.querySelector('.blog-list-blog-author').querySelectorAll('p')[1].childNodes[0].rawText
feed.item({
title: titleNode.rawText,
url: fixSiteUrl(link),
enclosure: {url: fixSiteUrl(imageUrl)},
author: author.childNodes[0].rawText,
description: description,
date: new Date(date)
})
} catch (ignore) {
// failed for some reason, probably date parsing
}
}
}
fs.writeFileSync('./site/blog/rss.xml', feed.xml({indent: true}))
}
generateRss()