-
Notifications
You must be signed in to change notification settings - Fork 6
/
generate.mjs
80 lines (71 loc) · 2.25 KB
/
generate.mjs
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
import fs from "fs/promises"
import jsonfeedToRSS from "jsonfeed-to-rss"
import podcast from "./config/podcast.json" assert { type: "json" }
function parseDuration(dur) {
const [hours, minutes, seconds] = dur.split(":").map(Number)
return hours * 3600 + minutes * 60 + seconds
}
async function main() {
const feed = {
version: "https://jsonfeed.org/version/1",
feed_url: "https://nuts.nl/going-nuts.xml",
home_page_url: "https://nuts.nl",
title: podcast.title,
description: podcast.summary,
_itunes: {
subtitle: podcast.subtitle,
author: podcast.author.name,
summary: podcast.summary,
// Add a random prefix so that the categories aren't valid iTunes categories
category: podcast.category.map(c => `_${c}`),
owner: {
name: podcast.author.name,
email: podcast.author.email,
},
image: podcast.image,
keywords: podcast.keywords.join(", "),
explicit: false
},
items: []
}
podcast.episodes.sort((a, b) =>
new Date(b.publishedAt).getTime() - new Date(a.publishedAt).getTime());
podcast.episodes.forEach(episode => {
feed.items.push({
id: episode.guid,
title: episode.title,
content_html: episode.summary,
image: podcast.image,
date_published: new Date(episode.publishedAt).toISOString(),
_itunes: {
author: podcast.author.name,
subtitle: episode.subtitle,
summary: episode.summary,
image: podcast.image,
explicit: false,
episodeType: "full"
},
attachments: [{
mime_type: "audio/mp3",
url: `https://nuts.nl/${episode.file}`,
size_in_bytes: episode.length,
duration_in_seconds: parseDuration(episode.duration),
}]
})
})
await fs.writeFile("public/going-nuts.xml", jsonfeedToRSS(feed, {
itunes: true,
language: "nl",
webMaster: podcast.author.email,
copyright: "©2022, copyleft gepubliceerd onder CC BY-SA 2.0 licentie"
})
// Fix for multiple categories that aren't supported
.replace(/<category>_/g, '<itunes:category text="')
.replace(/<\/category>/g, '"></itunes:category>'))
}
console.log("generating...")
main()
.then(() => console.log("done!"))
.catch(function (e) {
console.error(e)
})