-
Notifications
You must be signed in to change notification settings - Fork 13
/
generateFeed.js
45 lines (42 loc) Β· 1.63 KB
/
generateFeed.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
import { Feed } from "feed"
import GitFile from './classes/GitFile'
const max = (among, attr) => new Date(Math.max(...among.map(item => attr(item))))
const emptyFeed = new Feed({
title: 'The best books for developers β mustread.tech',
description: "Open-source and crowd-sourced book listing",
link: "http://mustread.tech",
id: "http://static.mustread.tech/rss.xml",
author: {
name: "Eduards Sizovs"
},
})
module.exports = books =>
Promise
.all(books
.map(book =>
new GitFile(book.location)
.revs()
.then(([firstRev]) => {
if (!firstRev) {
console.warn('π΅ Cannot get git history of ' + book.location)
return book
} else {
return { ...book, added: firstRev.commit.date() }
}
})
)
)
.then(stats => stats
.filter(stat => stat)
.reduce((feed, book) => {
feed.addItem({
id: "http://mustread.tech/books/isbn/" + book.objectID,
date: book.added,
link: "http://mustread.tech/books/isbn/" + book.objectID,
title: "Must-read book: " + book.title,
description: book.description.slice(0, 256) + "..."
})
feed.options.updated = max(feed.items, item => item.date)
return feed
}, emptyFeed))
.then(feed => feed.atom1())