53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
// generate-structure.js
|
|||
|
|
// Generates bible-structure.js from nlt-data.js
|
||
|
|
|
||
|
|
import fs from 'fs';
|
||
|
|
import path from 'path';
|
||
|
|
import { fileURLToPath } from 'url';
|
||
|
|
import { nltData } from './nlt-data.js';
|
||
|
|
|
||
|
|
const __filename = fileURLToPath(import.meta.url);
|
||
|
|
const __dirname = path.dirname(__filename);
|
||
|
|
|
||
|
|
function getSortedNumericKeys(object) {
|
||
|
|
return Object.keys(object)
|
||
|
|
.map((key) => Number(key))
|
||
|
|
.sort((a, b) => a - b);
|
||
|
|
}
|
||
|
|
|
||
|
|
function generateStructureFromNlt() {
|
||
|
|
const structure = {};
|
||
|
|
for (const book of Object.keys(nltData)) {
|
||
|
|
const chapters = nltData[book];
|
||
|
|
const chapterNumbers = getSortedNumericKeys(chapters);
|
||
|
|
const verseCounts = chapterNumbers.map((chapterNumber) => {
|
||
|
|
const versesObject = chapters[String(chapterNumber)];
|
||
|
|
const verseNumbers = getSortedNumericKeys(versesObject);
|
||
|
|
return verseNumbers.length;
|
||
|
|
});
|
||
|
|
structure[book] = verseCounts;
|
||
|
|
}
|
||
|
|
return structure;
|
||
|
|
}
|
||
|
|
|
||
|
|
function renderFile(structure) {
|
||
|
|
const chapterCounts = Object.fromEntries(
|
||
|
|
Object.entries(structure).map(([book, chapters]) => [book, chapters.length])
|
||
|
|
);
|
||
|
|
|
||
|
|
const banner = `// bible-structure.js\n// Auto-generated from nlt-data.js — do not edit manually\n\n`;
|
||
|
|
const exports = `export const bibleStructure = ${JSON.stringify(structure, null, 2)};\n\nexport const chapterCounts = Object.fromEntries(\n Object.entries(bibleStructure).map(([book, chapters]) => [book, chapters.length])\n);\n`;
|
||
|
|
return banner + exports;
|
||
|
|
}
|
||
|
|
|
||
|
|
function main() {
|
||
|
|
const structure = generateStructureFromNlt();
|
||
|
|
const outPath = path.join(__dirname, 'bible-structure.js');
|
||
|
|
fs.writeFileSync(outPath, renderFile(structure), 'utf-8');
|
||
|
|
console.log(`Wrote ${outPath}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
main();
|
||
|
|
|
||
|
|
|