unpack-whenwe-json.js - tweak to serialise lists of things as JSON

Which should work in YAML
This commit is contained in:
Nick Stokoe
2023-05-09 12:24:36 +01:00
parent af5c5ffde8
commit c2cb27d0f0

View File

@@ -1,3 +1,7 @@
/*
Reads in the Drupal node dump of WhenWe data from ./whenwe.json
Writes it converted to markdown with frontmatter, organised in subdirectories, in out/
*/
const data = require('./whenwe.json'); const data = require('./whenwe.json');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
@@ -8,7 +12,7 @@ const nhm = new NodeHtmlMarkdown({
}); });
function toYaml(data, body) { function toYaml(data, body) {
const frontmatter = Object.keys(data).sort().map(key => key+': '+(data[key] ? '"'+data[key]+'"' : '')).join("\n"); const frontmatter = Object.keys(data).sort().map(key => key+': '+(data[key] ? JSON.stringify(data[key]) : '')).join("\n");
return "---\n" + frontmatter + "\n---\n" + nhm.translate(body); return "---\n" + frontmatter + "\n---\n" + nhm.translate(body);
} }