You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/module/wiki/build.js

25 lines
888 B
JavaScript

const fs = require('fs');
const path = require('path');
const root = (name) => path.resolve(__dirname, name);
exports.prebuild = async () => {
const pages = fs.readdirSync(root('raw'));
const res = {};
for (const page of pages) {
// eslint-disable-next-line import/no-dynamic-require
const contents = require(root(`raw/${page}/contents.json`));
res[page] = [];
for (const id of contents) {
const content = {};
const c = fs.readFileSync(root(`raw/${page}/${id}.md`)).toString().split('\n');
// eslint-disable-next-line prefer-destructuring
content.title = c[0].split('# ')[1];
content.id = id;
content.content = c.splice(1, c.length - 1).join('\n');
res[page].push(content);
}
}
fs.writeFileSync(root('__build.json'), JSON.stringify(res));
};