-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatecomicfeed.js
73 lines (62 loc) · 1.94 KB
/
updatecomicfeed.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
62
63
64
65
66
67
68
69
70
71
const feedPath = "/srv/www/htdocs/comics/feed.xml";
const fs = require("fs");
const strips = require("/srv/www/htdocs/comics/strips.js");
console.log(strips);
function escapeQuotes(value) {
return value.replace(/["'&<>]/g, function (char) {
switch (char) {
case '"':
return """;
case "'":
return "'";
case "&":
return "&";
case "<":
return "<";
case ">":
return ">";
default:
return char;
}
});
}
// Function to create RSS feed as a string
function createRSSFeed(blogs) {
let rssFeed = `<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>DeaDvey</title>
<link>https://deadvey.com</link>
<description>Random ass comics inspired by XKCD</description>
<pubDate>${strips[strips.length - 1][1]} +0000</pubDate>
<lastBuildDate>${strips[strips.length - 1][1]} +0000</lastBuildDate>`;
// Add items to the feed
for (let index = strips.length - 1; index >= 0; index--) {
const currentStrip = strips[index]
const title = escapeQuotes(currentStrip[0]);
const content = `<img width='1500' src='/strips/${currentStrip[0]}'/>`;
const date = escapeQuotes(currentStrip[1]);
const totalContent = escapeQuotes(content)
rssFeed += `
<item>
<title>${title}</title>
<link>https://deadvey.com/comics/comic/${index}.html</link>
<description>${totalContent}</description>
<pubDate>${date} +0000</pubDate>
</item>`;
}
// Close the RSS feed
rssFeed += `
</channel>
</rss>
`;
return rssFeed;
}
feed = createRSSFeed(strips)
fs.writeFile(feedPath, feed, (err) => {
if (err) {
console.error('Error writing to the file:', err);
} else {
console.log('Data has been written to the file successfully.');
}
});