From abb10f112aa1248700e98caa0273f6afc5154a47 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 22 Jun 2024 20:07:43 -0400 Subject: Yes we are 2.6 now. --- generator/atomgen.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 generator/atomgen.js (limited to 'generator/atomgen.js') diff --git a/generator/atomgen.js b/generator/atomgen.js new file mode 100644 index 0000000..ede9771 --- /dev/null +++ b/generator/atomgen.js @@ -0,0 +1,46 @@ +//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'); +} -- cgit v1.2.3