codes:inject

This commit is contained in:
Matteias Collet 2020-07-01 07:44:30 +02:00
parent d78f1bf59b
commit f0574b22c9
5 changed files with 34 additions and 9 deletions

View file

@ -4,13 +4,14 @@ const jsdom = require('jsdom');
const jsonFilePath = path.join(__dirname, '../site/.vuepress/data/gameVersions.json'); const jsonFilePath = path.join(__dirname, '../site/.vuepress/data/gameVersions.json');
const codeVersions = ['GMSE01', 'GMSJ01', 'GMSP01', 'GMSJ0A']; const codeVersions = ['GMSE01', 'GMSJ01', 'GMSP01', 'GMSJ0A'];
const injectionTag = '<!-- injectionpoint -->';
const parseXml = xmlString => { const parseXml = (xmlString) => {
const codeCollection = new jsdom.JSDOM(xmlString).window.document.getElementsByTagName('code'); const codeCollection = new jsdom.JSDOM(xmlString).window.document.getElementsByTagName('code');
const codes = [...codeCollection]; const codes = [...codeCollection];
return codes.map(code => ({ return codes.map((code) => ({
author: parseTextNode(code, 'author'), author: parseTextNode(code, 'author'),
title: parseTextNode(code, 'title'), title: parseTextNode(code, 'title'),
description: parseTextNode(code, 'description'), description: parseTextNode(code, 'description'),
@ -22,11 +23,35 @@ const parseXml = xmlString => {
const parseTextNode = (node, identifier) => node.getElementsByTagName(identifier)[0].textContent; const parseTextNode = (node, identifier) => node.getElementsByTagName(identifier)[0].textContent;
const codes = JSON.parse(fs.readFileSync(jsonFilePath)); const codeJson = JSON.parse(fs.readFileSync(jsonFilePath));
for (let i = 0; i < codeVersions.length; i++) { for (let i = 0; i < codeVersions.length; i++) {
const xml = fs.readFileSync(path.join(__dirname, `../codes/${codeVersions[i]}.xml`)); const xml = fs.readFileSync(path.join(__dirname, `../codes/${codeVersions[i]}.xml`));
codes.find(c => c.identifier === codeVersions[i]).codes = parseXml(xml); codeJson.find((c) => c.identifier === codeVersions[i]).codes = parseXml(xml);
} }
fs.writeFileSync(jsonFilePath, JSON.stringify(codes)); fs.writeFileSync(jsonFilePath, JSON.stringify(codeJson));
for (let i = 0; i < codeVersions.length; i++) {
const reference = fs.readFileSync(
path.join(__dirname, `../site/code-references/${codeVersions[i].toLowerCase()}.md`),
);
if (!reference.includes(injectionTag)) {
throw new Error(`No injection tag found in ${codeVersions[i].toLowerCase()}.md`);
}
const fileContent = reference.split(injectionTag)[0] + injectionTag;
const codes = codeJson.find((c) => c.identifier === codeVersions[i]).codes;
codes.forEach((code) => {
const title = `#${code.title}`;
const author = `*${code.author.includes(',') ? 'Authors' : 'Author'} ${code.author}`;
const version = `*${code.version} (${code.date})`;
const description = code.description;
fileContent += `\n\n${title}\n\n${version}\n\n${author}\n\n${description}`;
});
fs.writeFileSync(`../site/code-references/${codeVersions[i].toLowerCase()}.md`, fileContent);
}

View file

@ -6,4 +6,4 @@ editLink: false
## List of available codes ## List of available codes
<CodeOverview gameVersion="GMSE01" /> <!-- injectionpoint -->

View file

@ -10,4 +10,4 @@ This site refers to version 1.0 of the NTSC-J release. For version 1.1 [click th
## List of available codes ## List of available codes
<CodeOverview gameVersion="GMSJ01" /> <!-- injectionpoint -->

View file

@ -10,4 +10,4 @@ This site refers to version 1.1 of the NTSC-J release. For version 1.0 [click th
## List of available codes ## List of available codes
<CodeOverview gameVersion="GMSJ0A" /> <!-- injectionpoint -->

View file

@ -6,4 +6,4 @@ editLink: false
## List of available codes ## List of available codes
<CodeOverview gameVersion="GMSP01" /> <!-- injectionpoint -->