//Copyright Chris Xiong 2024 //License: Expat (MIT) module.exports = { gen_atom:function(list, config) { _gen_atom(list, config); } }; const jsdom=require('jsdom'); const path=require('path'); const fs=require('fs'); const htmlescape=require('./util').htmlescape; function _gen_atom(list, config) { const sorted_list = list.toSorted((a, b) => (new Date(b.date)).getTime() - (new Date(a.date)).getTime()); let xmlbuf = ``; xmlbuf += ``; xmlbuf += `SSBS`; xmlbuf += `${new Date().toISOString()}`; xmlbuf += ``; xmlbuf += ``; xmlbuf += `${config.atom_url}`; xmlbuf += `${config.atom_title}`; xmlbuf += `${config.atom_subtitle}`; xmlbuf += `${config.atom_icon}`; xmlbuf += `${config.atom_icon}`; for (let i = 0; i < sorted_list.length && i < config.atom_feed_nposts; ++i) { const p = sorted_list[i]; const postpath = path.join(path.join(config.dest_dir,'post'), `${p.file}.html`); const contfull = fs.readFileSync(postpath, 'utf8'); const doc = new jsdom.JSDOM(contfull).window.document; const content = doc.querySelector('article').innerHTML; const footnotes = doc.getElementById('notediv').outerHTML; const link = `https://chrisoft.org/blog/post/${p.file}.html`; xmlbuf += ``; xmlbuf += `${htmlescape(p.title)}`; xmlbuf += ``; xmlbuf += `${new Date(p.date).toISOString()}`; xmlbuf += `${new Date(p.mdate).toISOString()}`; xmlbuf += `${link}`; xmlbuf += `${config.atom_author}` xmlbuf += `
${footnotes}]]>
`; xmlbuf += `
`; } xmlbuf += `
`; fs.writeFileSync(path.join(config.dest_dir, "atom.xml"), xmlbuf ,'utf8'); }