diff --git a/scripts/clean_codes.js b/scripts/clean_codes.js index 64bda3d..de1eac7 100644 --- a/scripts/clean_codes.js +++ b/scripts/clean_codes.js @@ -2,7 +2,6 @@ const fs = require('fs'); const path = require('path'); const JSON_FILE_PATH = path.join(__dirname, '../site/.vuepress/data/gameVersions.json'); -const CODE_VERSIONS = ['GMSE01', 'GMSJ01', 'GMSP01', 'GMSJ0A']; const INJECTION_TAG = ''; const locales = require(path.join(__dirname, '../site/.vuepress/i18n/locales.json')); @@ -19,23 +18,18 @@ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(codeJson)); Object.keys(locales).forEach((locale) => { // Clear the code reference - for (let i = 0; i < CODE_VERSIONS.length; i++) { - const filePath = path.join( - __dirname, - `../site/${locale.trim()}/code-reference/${CODE_VERSIONS[i].toLowerCase()}.md`, - ); + const filePath = path.join(__dirname, `../site/${locale.trim()}/code-reference/index.md`); - // Get the current reference - const reference = fs.readFileSync(filePath).toString(); + // Get the current reference + const reference = fs.readFileSync(filePath).toString(); - if (!reference.includes(INJECTION_TAG)) { - throw new Error(`No injection tag found in ${CODE_VERSIONS[i].toLowerCase()}.md`); - } - - // Clear everything after the injection tag - let fileContent = reference.split(INJECTION_TAG)[0] + INJECTION_TAG; - - // Save the reference file - fs.writeFileSync(filePath, fileContent); + if (!reference.includes(INJECTION_TAG)) { + throw new Error(`No injection tag found in ${locale.trim()}/code-reference/index.md`); } + + // Clear everything after the injection tag + let fileContent = reference.split(INJECTION_TAG)[0] + INJECTION_TAG; + + // Save the reference file + fs.writeFileSync(filePath, fileContent); }); diff --git a/scripts/inject_codes.js b/scripts/inject_codes.js index f7386dd..2eee52c 100644 --- a/scripts/inject_codes.js +++ b/scripts/inject_codes.js @@ -312,51 +312,66 @@ for (let i = 0; i < CODE_VERSIONS.length; i++) { // Save the codeJSON with the updated codes fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(codeJson)); +const parseReferenceList = (xmlString) => { + const codeCollection = new JSDOM(xmlString, { + contentType: 'text/xml', + }).window.document.getElementsByTagName('code'); + + const codes = [...codeCollection]; + return codes.map((code) => ({ + author: readTextNode(code, 'author'), + title: localizeNode(code, 'title'), + description: localizeMarkdown(code, 'description'), + version: readTextNode(code, 'version'), + date: readTextNode(code, 'date'), + gameVersions: CODE_VERSIONS.filter( + (v) => code.querySelector(`source[version='${v}']`)?.textContent != null, + ), + })); +}; + +const REFERENCE_CODE_LIST = parseReferenceList(xml); + Object.keys(locales).forEach((locale) => { const localeKey = locales[locale].lang; const localeLabels = require(`../site/.vuepress/i18n/${localeKey}.json`); - // Populate the code reference - for (let i = 0; i < CODE_VERSIONS.length; i++) { - // Load the target reference file - const filePath = path.join( - __dirname, - `../site/${locale.trim('/')}/code-reference/${CODE_VERSIONS[i].toLowerCase()}.md`, - ); + // Load the target reference file + const referenceFile = path.join(__dirname, `../site/${locale.trim('/')}/code-reference/index.md`); + const referenceContent = fs.readFileSync(referenceFile).toString(); - // Get the current reference - const reference = fs.readFileSync(filePath).toString(); - - if (!reference.includes(INJECTION_TAG)) { - throw new Error(`No injection tag found in ${CODE_VERSIONS[i].toLowerCase()}.md`); - } - - // Everything after the injection tag is deleted from the file - let fileContent = reference.split(INJECTION_TAG)[0] + INJECTION_TAG; - - // Order codes by their localized title - const codes = codeJson - .find((c) => c.identifier === CODE_VERSIONS[i]) - .codes.sort((a, b) => - a.title.find((t) => t.lang === localeKey).content > - b.title.find((t) => t.lang === localeKey).content - ? 1 - : -1, - ); - - // Create a semi-markdown version for all codes - codes.forEach((code) => { - const title = `### ${code.title.find((t) => t.lang === localeKey).content}`; - const author = `*${ - code.author.includes(',') ? localeLabels.codeinfo.authors : localeLabels.codeinfo.author - } ${code.author}*`; - const version = `*${localeLabels.codeinfo.version} ${code.version} (${code.date})*`; - const description = code.description.find((d) => d.lang === localeKey).content; - - fileContent += `\n\n${title.trim()}\n\n${version.trim()} \n${author.trim()}\n\n${description.trim()}\n\n`; - }); - - // Save the reference file - fs.writeFileSync(filePath, fileContent); + if (!referenceContent.includes(INJECTION_TAG)) { + throw new Error(`No injection tag found in ${locale.trim('/')}/code-reference/index.md`); } + + let fileContent = referenceContent.split(INJECTION_TAG)[0] + INJECTION_TAG; + + // Order codes by their localized title + const codes = REFERENCE_CODE_LIST.sort((a, b) => + a.title.find((t) => t.lang === localeKey).content > + b.title.find((t) => t.lang === localeKey).content + ? 1 + : -1, + ); + + // Create a semi-markdown version for all codes + codes.forEach((code) => { + const title = `## ${code.title.find((t) => t.lang === localeKey).content}`; + const author = `*${ + code.author.includes(',') ? localeLabels.codeinfo.authors : localeLabels.codeinfo.author + } ${code.author}*`; + const version = `*${localeLabels.codeinfo.version} ${code.version} (${code.date})*`; + const description = code.description.find((d) => d.lang === localeKey).content; + const availableFor = CODE_VERSIONS.filter((v) => code.gameVersions.includes(v)) + .map((v) => ``) + .join(' '); + const notAvailableFor = CODE_VERSIONS.filter((v) => !code.gameVersions.includes(v)) + .map((v) => ``) + .join(' '); + + fileContent += `\n\n${title.trim()}\n\n${availableFor} ${notAvailableFor} \n${version.trim()} \n${author.trim()}\n\n${description.trim()}\n\n`; + }); + + // Save the reference file + fs.writeFileSync(referenceFile, fileContent); }); diff --git a/site/.vuepress/components/VersionCards.vue b/site/.vuepress/components/VersionCards.vue deleted file mode 100644 index ca668e3..0000000 --- a/site/.vuepress/components/VersionCards.vue +++ /dev/null @@ -1,68 +0,0 @@ - - - - {{ getLabel(`common.${version.identifier}`) }} - - - - - - - diff --git a/site/.vuepress/components/VersionTag.vue b/site/.vuepress/components/VersionTag.vue new file mode 100644 index 0000000..2fe6b4b --- /dev/null +++ b/site/.vuepress/components/VersionTag.vue @@ -0,0 +1,41 @@ + + {{ + getLabel(version) + }} + + + + + diff --git a/site/code-reference/gmse01.md b/site/code-reference/gmse01.md deleted file mode 100644 index 453078c..0000000 --- a/site/code-reference/gmse01.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSE01 (NTSC-U / North America) - -## List of available codes - - diff --git a/site/code-reference/gmsj01.md b/site/code-reference/gmsj01.md deleted file mode 100644 index 4e53e05..0000000 --- a/site/code-reference/gmsj01.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSJ01 (NTSC-J / Japan) - -::: tip -This site refers to version 1.0 of the NTSC-J release. For version 1.1 [click this link](/code-reference/gmsj0a.html). -::: - -## List of available codes - - diff --git a/site/code-reference/gmsj0a.md b/site/code-reference/gmsj0a.md deleted file mode 100644 index 2e8dc50..0000000 --- a/site/code-reference/gmsj0a.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSJ01 (NTSC-J / Japan) - -::: tip -This site refers to version 1.1 of the NTSC-J release. For version 1.0 [click this link](/code-reference/gmsj01.html). -::: - -## List of available codes - - diff --git a/site/code-reference/gmsp01.md b/site/code-reference/gmsp01.md deleted file mode 100644 index 4fa215b..0000000 --- a/site/code-reference/gmsp01.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSP01 (PAL / Europe) - -## List of available codes - - diff --git a/site/code-reference/index.md b/site/code-reference/index.md index e087024..100c270 100644 --- a/site/code-reference/index.md +++ b/site/code-reference/index.md @@ -1,7 +1,8 @@ --- +sidebar: auto editLink: false --- # Code Reference - + diff --git a/site/de/code-reference/gmse01.md b/site/de/code-reference/gmse01.md deleted file mode 100644 index 886eca3..0000000 --- a/site/de/code-reference/gmse01.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSE01 (NTSC-U / Nord Amerika) - -## Liste der verfügbaren Codes - - diff --git a/site/de/code-reference/gmsj01.md b/site/de/code-reference/gmsj01.md deleted file mode 100644 index 8303d87..0000000 --- a/site/de/code-reference/gmsj01.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSJ01 (NTSC-J / Japan) - -::: tip -Diese Seite bezieht sich auf NTSC-J Version 1.0. Für version 1.1 [klicke diesen link](/de/code-reference/gmsj0a.html) -::: - -## Liste der verfügbaren Codes - - diff --git a/site/de/code-reference/gmsj0a.md b/site/de/code-reference/gmsj0a.md deleted file mode 100644 index 5ce814d..0000000 --- a/site/de/code-reference/gmsj0a.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSJ01 (NTSC-J / Japan) - -::: tip -Diese Seite bezieht sich auf NTSC-J Version 1.1. Für version 1.0 [klicke diesen link](/de/code-reference/gmsj01.html) -::: - -## Liste der verfügbaren Codes - - diff --git a/site/de/code-reference/gmsp01.md b/site/de/code-reference/gmsp01.md deleted file mode 100644 index 2182537..0000000 --- a/site/de/code-reference/gmsp01.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSP01 (PAL / Europa) - -## Liste der verfügbaren Codes - - diff --git a/site/de/code-reference/index.md b/site/de/code-reference/index.md index 4d18e42..1d77685 100644 --- a/site/de/code-reference/index.md +++ b/site/de/code-reference/index.md @@ -1,7 +1,8 @@ --- +sidebar: auto editLink: false --- # Code Referenz - + diff --git a/site/fr/code-reference/gmse01.md b/site/fr/code-reference/gmse01.md deleted file mode 100644 index 3e605ac..0000000 --- a/site/fr/code-reference/gmse01.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSE01 (NTSC-U / Amérique du Nord) - -## Liste des codes disponibles - - diff --git a/site/fr/code-reference/gmsj01.md b/site/fr/code-reference/gmsj01.md deleted file mode 100644 index 6c71250..0000000 --- a/site/fr/code-reference/gmsj01.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSJ01 (NTSC-J / Japon) - -::: tip -Cette page concerne la version 1.0 de la région NTSC-J. Pour la version 1.1 [cliquez sur ce lien](/fr/code-reference/gmsj0a.html). -::: - -## Liste des codes disponibles - - diff --git a/site/fr/code-reference/gmsj0a.md b/site/fr/code-reference/gmsj0a.md deleted file mode 100644 index 51ecfb5..0000000 --- a/site/fr/code-reference/gmsj0a.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSJ01 (NTSC-J / Japon) - -::: tip -Cette page concerne la version 1.1 de la région NTSC-J. Pour la version 1.0 [cliquez sur ce lien](/fr/code-reference/gmsj01.html). -::: - -## Liste des codes disponibles - - diff --git a/site/fr/code-reference/gmsp01.md b/site/fr/code-reference/gmsp01.md deleted file mode 100644 index 7c87c1c..0000000 --- a/site/fr/code-reference/gmsp01.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSP01 (PAL / Europe) - -## Liste des codes disponibles - - diff --git a/site/fr/code-reference/index.md b/site/fr/code-reference/index.md index 7556431..8a1900d 100644 --- a/site/fr/code-reference/index.md +++ b/site/fr/code-reference/index.md @@ -1,7 +1,8 @@ --- +sidebar: auto editLink: false --- # Référence des codes - + diff --git a/site/ja/code-reference/gmse01.md b/site/ja/code-reference/gmse01.md deleted file mode 100644 index f36d0ed..0000000 --- a/site/ja/code-reference/gmse01.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSE01 (NTSC-U / 北アメリカ) - -## チートコードリスト - - diff --git a/site/ja/code-reference/gmsj01.md b/site/ja/code-reference/gmsj01.md deleted file mode 100644 index a9c4502..0000000 --- a/site/ja/code-reference/gmsj01.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSJ01 (NTSC-J / 日本語) - - -::: tip -このページはJP1.0(NTSC-J 1.0)のチートコードリストです。[JP1.1はこちら](/ja/code-reference/gmsj0a.html) -::: - -## チートコードリスト - - - - diff --git a/site/ja/code-reference/gmsj0a.md b/site/ja/code-reference/gmsj0a.md deleted file mode 100644 index fb6cd1e..0000000 --- a/site/ja/code-reference/gmsj0a.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - - - -# GMSJ01 (NTSC-J / 日本語) - -::: tip -このページはJP1.1(NTSC-J 1.1)のチートコードリストです。[JP1.0はこちら](/ja/code-reference/gmsj01.html) -::: - -## チートコードリスト - - - - diff --git a/site/ja/code-reference/gmsp01.md b/site/ja/code-reference/gmsp01.md deleted file mode 100644 index fa19721..0000000 --- a/site/ja/code-reference/gmsp01.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -sidebar: auto -editLink: false ---- - -# GMSP01 (PAL / ヨーロッパ) - -## チートコードリスト - - diff --git a/site/ja/code-reference/index.md b/site/ja/code-reference/index.md index 76b5ac5..4e1fd7e 100644 --- a/site/ja/code-reference/index.md +++ b/site/ja/code-reference/index.md @@ -1,7 +1,8 @@ --- +sidebar: auto editLink: false --- # チートコード一覧 - +