mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig.space.git
synced 2025-12-14 00:36:48 +00:00
Refactor feed generating and file revisioning
This commit is contained in:
29
tasks/generate_feed.js
Normal file
29
tasks/generate_feed.js
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
const { XMLBuilder, XMLValidator } = require('fast-xml-parser')
|
||||
const xmlFormat = require('xml-formatter')
|
||||
const { write } = require('../helpers')
|
||||
const feed = require('../generated/feed.json')
|
||||
|
||||
const json2xmlOpts = {
|
||||
attributeNamePrefix: '',
|
||||
attributesGroupName: '__attr',
|
||||
ignoreAttributes: false,
|
||||
cdataPropName: '__cdata',
|
||||
indentBy: ' '
|
||||
}
|
||||
const builder = new XMLBuilder(json2xmlOpts)
|
||||
|
||||
// Load and adapt feed
|
||||
const outputXML = builder.build(feed)
|
||||
const validation = XMLValidator.validate(outputXML)
|
||||
if (validation) {
|
||||
write(
|
||||
'dist/feed.xml',
|
||||
xmlFormat(outputXML, {
|
||||
indentation: json2xmlOpts.indentBy,
|
||||
collapseContent: true
|
||||
})
|
||||
)
|
||||
} else {
|
||||
console.error(validation.err)
|
||||
}
|
||||
Reference in New Issue
Block a user