diff --git a/scripts/inject_codes.js b/scripts/inject_codes.js
index fb278f4..92fbcef 100644
--- a/scripts/inject_codes.js
+++ b/scripts/inject_codes.js
@@ -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 = '';
-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);
+}
diff --git a/site/code-reference/gmse01.md b/site/code-reference/gmse01.md
index d6cb63b..61cc245 100644
--- a/site/code-reference/gmse01.md
+++ b/site/code-reference/gmse01.md
@@ -6,4 +6,4 @@ editLink: false
## List of available codes
-
+
diff --git a/site/code-reference/gmsj01.md b/site/code-reference/gmsj01.md
index 4d3c4aa..f7a059b 100644
--- a/site/code-reference/gmsj01.md
+++ b/site/code-reference/gmsj01.md
@@ -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
-
+
diff --git a/site/code-reference/gmsj0a.md b/site/code-reference/gmsj0a.md
index 4a89cb4..9b9469b 100644
--- a/site/code-reference/gmsj0a.md
+++ b/site/code-reference/gmsj0a.md
@@ -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
-
+
diff --git a/site/code-reference/gmsp01.md b/site/code-reference/gmsp01.md
index 996faf4..2fc1b74 100644
--- a/site/code-reference/gmsp01.md
+++ b/site/code-reference/gmsp01.md
@@ -6,4 +6,4 @@ editLink: false
## List of available codes
-
+