-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
41 lines (34 loc) · 1.04 KB
/
script.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
const parser = require("fast-xml-parser");
const https = require("https");
const fs = require("fs").promises;
const path = require("path");
https
.get("https://il3ven.hashnode.dev/rss.xml", (resp) => {
let data = "";
// A chunk of data has been received.
resp.on("data", (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on("end", async () => {
const feed = parser.parse(data);
const articles = feed.rss.channel.item
.slice(0, 3)
.map((item) => `1. [${item.title}](${item.link})`);
console.log(articles);
const readme = await fs.readFile(
path.join(__dirname, "./README.md"),
"utf-8"
);
await fs.writeFile(
path.join(__dirname, "./README.md"),
readme.replace(
/(### My last 3 blogs)(.*)(_Updated using GitHub Actions_ )/is,
`$1\n\n${articles.join("\n")}\n\n$3`
)
);
});
})
.on("error", (err) => {
console.log("Error: " + err.message);
});