Files
5etools-mirror-2.github.io/node/generate-nav-adventure-book-index.js
TheGiddyLimit 2eeeb0771b v1.209.0
2024-07-10 20:47:40 +01:00

43 lines
999 B
JavaScript

import fs from "fs";
import "../js/parser.js";
import "../js/utils.js";
import * as ut from "./util.js";
const _PROPS_TO_INDEX = [
"name",
"id",
"source",
"parentSource",
"group",
"level",
"storyline",
"published",
"publishedOrder",
];
const _METAS = [
{
file: `data/adventures.json`,
prop: "adventure",
},
{
file: `data/books.json`,
prop: "book",
},
];
const out = _METAS.mergeMap(({file, prop}) => {
return {[prop]: ut.readJson(file)[prop]
.map(it => _PROPS_TO_INDEX.mergeMap(prop => {
const sub = {[prop]: it[prop]};
// Expand the parent source, as the navbar doesn't wait for load completion.
// (Although in this instance, it actually does, but this keeps the API sane.)
if (prop === "parentSource" && it[prop]) sub.parentName = Parser.sourceJsonToFull(it[prop]);
return sub;
})),
};
});
fs.writeFileSync("data/generated/gendata-nav-adventure-book-index.json", JSON.stringify(out), "utf8");
console.log("Generated navbar adventure/book index.");