codes:inject
This commit is contained in:
parent
d78f1bf59b
commit
f0574b22c9
5 changed files with 34 additions and 9 deletions
|
@ -4,13 +4,14 @@ const jsdom = require('jsdom');
|
|||
|
||||
const jsonFilePath = path.join(__dirname, '../site/.vuepress/data/gameVersions.json');
|
||||
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 codes = [...codeCollection];
|
||||
|
||||
return codes.map(code => ({
|
||||
return codes.map((code) => ({
|
||||
author: parseTextNode(code, 'author'),
|
||||
title: parseTextNode(code, 'title'),
|
||||
description: parseTextNode(code, 'description'),
|
||||
|
@ -22,11 +23,35 @@ const parseXml = xmlString => {
|
|||
|
||||
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++) {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -6,4 +6,4 @@ editLink: false
|
|||
|
||||
## List of available codes
|
||||
|
||||
<CodeOverview gameVersion="GMSE01" />
|
||||
<!-- injectionpoint -->
|
||||
|
|
|
@ -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
|
||||
|
||||
<CodeOverview gameVersion="GMSJ01" />
|
||||
<!-- injectionpoint -->
|
||||
|
|
|
@ -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
|
||||
|
||||
<CodeOverview gameVersion="GMSJ0A" />
|
||||
<!-- injectionpoint -->
|
||||
|
|
|
@ -6,4 +6,4 @@ editLink: false
|
|||
|
||||
## List of available codes
|
||||
|
||||
<CodeOverview gameVersion="GMSP01" />
|
||||
<!-- injectionpoint -->
|
||||
|
|
Loading…
Reference in a new issue