Skip to content

Commit 56e3c47

Browse files
committed
Create generate-glossary-json.js
1 parent 47826a6 commit 56e3c47

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

scripts/generate-glossary-json.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const glossaryFilePath = path.join(__dirname, '../src/pages/glossary.mdx');
4+
const outputJsonPath = path.join(__dirname, '../static/glossary.json');
5+
6+
const generateGlossaryJson = () => {
7+
const glossaryContent = fs.readFileSync(glossaryFilePath, 'utf-8');
8+
const glossaryLines = glossaryContent.split('\n');
9+
10+
let glossary = {};
11+
let currentTerm = '';
12+
13+
glossaryLines.forEach((line) => {
14+
if (line.startsWith('## ')) {
15+
// Extract the term (strip the '## ' prefix)
16+
currentTerm = line.replace('## ', '').trim();
17+
} else if (line.startsWith('# ')) {
18+
// Skip heading 1 (`# `) lines
19+
currentTerm = ''; // Reset the current term for heading 1 lines
20+
} else if (line.trim() !== '' && currentTerm !== '') {
21+
// Add the definition to the current term (only if a valid term is set)
22+
glossary[currentTerm] = line.trim();
23+
}
24+
});
25+
26+
// Write glossary to glossary.json
27+
fs.writeFileSync(outputJsonPath, JSON.stringify(glossary, null, 2));
28+
console.log('glossary.json generated successfully.');
29+
};
30+
31+
generateGlossaryJson();

0 commit comments

Comments
 (0)