import RSS from "rss"; import i18n from "./i18n.mjs"; import mime from "mime/lite"; const getRSS = (articles, baseUrl, lang, rssName) => { console.log(i18n[lang]["rss"]["title"]); const feed_url = encodeURI( `${baseUrl}rss${(rssName || "rss_full").includes("full") ? "" : "-main"}.xml`, ); const rssFeed = new RSS({ title: i18n[lang][rssName || "rss_full"]["title"], description: i18n[lang][rssName || "rss_full"]["description"], /* custom_namespaces: { visible_description: i18n[lang][rssName || "rss_full"]["description"], }, */ site_url: encodeURI("https://ache.one"), feed_url, canonical: feed_url, site_url: encodeURI(baseUrl), image_url: encodeURI(`${baseUrl}ache.png`), language: lang, pubDate: Date(), ttl: "1440", }); for (const post of articles.slice(0, 10)) { const image_url = post.imageUrl[0] != "/" ? `/${post.imageUrl}` : post.imageUrl; if (!post.introDesc) { throw new Error(`Article intro is empty: ${post.title}`); } const item = { title: post.title, description: post.introDesc, image_url: encodeURI(image_url), url: encodeURI(`${baseUrl}${post.url.slice(1)}`), author: "ache", date: post.metaData.pubDateISO, categories: post.metaData.tags, /* custom_elements: [ { image: [ { url: image_url }, { link: `${baseUrl}${post.url.slice(1)}` }, { title: post.title }, ], }, ], */ }; if (post.imageSize) { item.enclosure = { url: encodeURI(`${baseUrl}${image_url}`), type: mime.getType(image_url), length: post.imageSize?.toString(), }; } rssFeed.item(item); } const mainOnly = (rssName || "rss_full").includes("full") ? "" : "_main"; return rssFeed .xml({ indent: false }) .replace( /<\?xml version="1.0" encoding="UTF-8"\?>/g, `\n\n`, ) .replace(/xmlns:visible_description/, `visible_description`); }; export default getRSS;