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
|
import RSS from "rss";
import i18n from "./i18n.mjs";
const getRSS = (articles, baseUrl, lang, rssName) => {
console.log(i18n[lang]["rss"]["title"]);
const rssFeed = new RSS({
title: i18n[lang][rssName || "rss"]["title"],
description: i18n[lang][rssName || "rss"]["description"],
// eslint-disable-next-line camelcase
custom_namespaces: {
visible_description: i18n[lang][rssName || "rss"]["description"],
},
site_url: "https://ache.one",
feed_url: `${baseUrl}rss.xml`,
canonical: `${baseUrl}rss.xml`,
// eslint-disable-next-line camelcase
site_url: baseUrl,
// eslint-disable-next-line camelcase
image_url: `${baseUrl}ache.svg`,
language: lang,
pubDate: Date(),
ttl: "1440",
});
for (const article of articles.slice(0, 10)) {
let image_url =
article.imageUrl[0] != "/" ? `/${article.imageUrl}` : article.imageUrl;
rssFeed.item({
title: article.title,
description: "<article>" + article.content + "</article>",
// eslint-disable-next-line camelcase
image_url,
url: `${baseUrl}articles/${article.name}`,
guid: article.domTitle,
author: "ache",
date: article.metaData.pubDateISO,
categories: article.metaData.tags,
// eslint-disable-next-line camelcase
custom_elements: [{ logo: image_url }, { intro: article.introDesc }],
});
}
return rssFeed
.xml({ indent: false })
.replace(
/<\?xml version="1.0" encoding="UTF-8"\?>/g,
'<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/style.xsl"?>',
);
};
export default getRSS;
|