summaryrefslogtreecommitdiff
path: root/src/build/rss.mjs
blob: 606cdef63b309c8cd9c95d87a846f295529435a9 (plain)
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
import RSS from 'rss';

const siteUrl = 'https://ache.one';

const getRSS = articles => {
  const rssFeed = new RSS({
    title: 'ache: Blog personnel',
    description: 'Programmation, Algorithmique, Système, *pick you poison*',
    // eslint-disable-next-line camelcase
    feed_url: `${siteUrl}/feed.xml`,
    // eslint-disable-next-line camelcase
    site_url: siteUrl,
    // eslint-disable-next-line camelcase
    image_url: `${siteUrl}/ache.svg`,
    language: 'fr',
    pubDate: (new Date().toLocaleString()),
    ttl: '1440',
    // eslint-disable-next-line camelcase
    custom_elements: ['<?xml-stylesheet type="text/css" href="http://localhost:8080/s/css/style.css" ?>'],
  });

  for (const article of articles.slice(0, 10)) {
    rssFeed.item({
      title: article.title,
      description: '<article>' + article.content + '</article>',
      // eslint-disable-next-line camelcase
      image_url: article.imageUrl,
      url: `${siteUrl}/articles/${article.domTitle}`,
      guid: article.domTitle,
      author: 'ache',
      // eslint-disable-next-line camelcase
      custom_elements: [
        {logo: article.imageUrl},
        {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;