-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrss-builder.ts
37 lines (35 loc) · 1.47 KB
/
rss-builder.ts
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
const data = JSON.parse(Deno.readTextFileSync('./feeds.json'));
import {LANGUAGES, TIME_PERIODS} from "./src/app.constants.ts";
const XMLEncode = (str: string) => {
return str.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
Object.keys(data).forEach((language) => {
Object.keys(data[language]).forEach((timePeriod) => {
const langLabel = LANGUAGES.find(l => l.id === language)?.label || '';
const timeLabel = TIME_PERIODS.find(t => t.id === timePeriod)?.label || '';
let langId;
if (language === '') langId = 'all';
let RSS = `<rss version="2.0">
<channel>
<title>${XMLEncode(`GitHub Trending ${langLabel} - ${timeLabel}`)}</title>
<description>${XMLEncode(`Daily Trending ${langLabel} repositories on GitHub`)}</description>
<pubDate>${new Date().toUTCString()}</pubDate>
<link>https://github-rss.alexi.sh</link>`
data[language][timePeriod].forEach((repo) => {
RSS += `
<item>
<title>${XMLEncode(`${repo.name}`)}</title>
<description>${XMLEncode(`${repo.description}`)}</description>
<link>${XMLEncode(`https://github.com/${repo.name}`)}</link>
</item>`
});
RSS += `
</channel>
</rss>`
Deno.writeTextFile(`./static/feeds/${timePeriod}/${ langId ? decodeURIComponent(langId) : decodeURIComponent(language)}.xml`, RSS);
});
});