1+ import fs from 'fs' ;
2+ import { Feed } from 'feed' ;
3+ import { blogpostsDetails } from '../src/components/blog/blogpostsDetails.js' ;
4+ import path from 'path' ;
5+ import { fileURLToPath } from 'url' ;
6+ const __filename = fileURLToPath ( import . meta. url ) ;
7+ const __dirname = path . dirname ( __filename ) ;
8+
9+ const outputDir = path . join ( __dirname , '../static' ) ;
10+ if ( ! fs . existsSync ( outputDir ) ) {
11+ fs . mkdirSync ( outputDir , { recursive : true } ) ;
12+ }
13+
14+ const generateAtomFeedFromBlogDetails = ( feed , blogpostsDetails , nbOfBlogPosts ) => {
15+ let posts = [ ] ;
16+ for ( let i = 0 ; i < nbOfBlogPosts ; i ++ ) {
17+ const blogpost = blogpostsDetails [ i ] ;
18+ posts . push ( {
19+ title : blogpost . title ,
20+ link : blogpost . url ,
21+ summary : blogpost . summary ,
22+ date : new Date ( blogpost . date ) ,
23+ authors : blogpost . authors . split ( ',' ) ,
24+ } )
25+ } ;
26+
27+ posts . forEach ( ( post ) => {
28+ feed . addItem ( {
29+
30+ title : post . title ,
31+ id : post . link ,
32+ link : post . link ,
33+ date : new Date ( post . date ) ,
34+ author : [ { name : post . authors } ] ,
35+ content : post . summary
36+
37+ } ) ;
38+
39+ } )
40+ return feed ;
41+ }
42+ const AtomFeedLast20 = new Feed ( {
43+ title : 'Recent blog posts featured by QuantStack team' ,
44+ description : 'Atom feed for QuantStack website blog page' ,
45+ id : 'https://quantstack.net/' ,
46+ link : 'https://quantstack.net/' ,
47+ language : 'en' ,
48+ updated : new Date ( ) ,
49+ feedLinks : {
50+ atom : 'https://quantstack.net/atom.xml' ,
51+ } ,
52+ author : {
53+ name : 'QuantStack Team' ,
54+ link : 'https://quantstack.net' ,
55+ } ,
56+ } ) ;
57+
58+
59+ const updatedFeedLast20 = generateAtomFeedFromBlogDetails ( AtomFeedLast20 , blogpostsDetails , 20 ) ;
60+ const xml = updatedFeedLast20 . atom1 ( ) ;
61+ fs . writeFileSync ( path . join ( outputDir , 'atom.xml' ) , xml ) ;
62+
63+ const AtomFeedAll = new Feed ( {
64+ title : 'All blog posts featured by QuantStack team' ,
65+ description : 'Atom feed for QuantStack website blog page' ,
66+ feed_url : 'https://quantstack.net/atom_all.xml' ,
67+ site_url : 'https://quantstack.net' ,
68+ language : 'en' ,
69+ } ) ;
70+
71+
72+ const updatedFeedAll = generateAtomFeedFromBlogDetails ( AtomFeedAll , blogpostsDetails , blogpostsDetails . length )
73+ fs . writeFileSync ( path . join ( outputDir , 'atom_all.xml' ) , updatedFeedAll . atom1 ( { indent : true } ) ) ;
0 commit comments