merge code references into one

This commit is contained in:
Matteias Collet 2021-11-05 01:29:56 +00:00 committed by GitHub
parent 9462696fb7
commit 675015822e
24 changed files with 116 additions and 329 deletions

View file

@ -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 = '<!-- injectionpoint -->';
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);
});

View file

@ -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) => `<VersionTag version="${v}" supported="true" />`)
.join(' ');
const notAvailableFor = CODE_VERSIONS.filter((v) => !code.gameVersions.includes(v))
.map((v) => `<VersionTag version="${v}" supported="false" />`)
.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);
});

View file

@ -1,68 +0,0 @@
<template>
<div class="wrapper">
<div
v-for="(version, idx) in gameVersions"
v-bind:key="idx"
class="card"
@click="onCardClick(version)"
>
<h3>{{ getLabel(`common.${version.identifier}`) }}</h3>
</div>
</div>
</template>
<script>
// Data
import gameVersions from '../data/gameVersions.json';
import locales from '../i18n/locales.json';
// Util
import { translate } from '../i18n/localeHelper';
export default {
data() {
return {
gameVersions,
};
},
methods: {
onCardClick(v) {
let localePath = '';
Object.keys(locales).forEach((l) => {
if (locales[l].lang === this.$lang) localePath = l.replace(/\/+$/, '');
});
window.location.href = `${localePath}/code-reference/${v.identifier.toLowerCase()}.html`;
},
getLabel(key) {
return translate(key, this.$lang);
},
},
};
</script>
<style scoped>
.wrapper {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.card {
width: 300px;
max-width: 100%;
margin: 5px;
padding: 15px;
background-color: #f3f5f7;
border-left: 0.5rem solid #42b983;
cursor: pointer;
text-align: center;
color: #3eaf7c;
}
.card:hover {
background-color: #e5f0eb;
}
</style>

View file

@ -0,0 +1,41 @@
<template>
<span :class="[true, 'true'].includes(supported) ? 'card pcard' : 'card ncard'">{{
getLabel(version)
}}</span>
</template>
<script>
import { translate } from '../i18n/localeHelper';
export default {
props: ['version', 'supported'],
data() {
return {};
},
methods: {
getLabel(version) {
return translate(`common.${version}`, this.$lang);
},
},
};
</script>
<style scoped>
.card {
font-size: 0.8em;
display: inline-block;
color: white;
padding: 4px 8px;
border-radius: 6px;
white-space: nowrap;
margin-top: 10px;
}
.pcard {
background: #3eaf7c;
}
.ncard {
background: #df4d21e0;
}
</style>

View file

@ -1,10 +0,0 @@
---
sidebar: auto
editLink: false
---
# GMSE01 (NTSC-U / North America)
## List of available codes
<!-- injectionpoint -->

View file

@ -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
<!-- injectionpoint -->

View file

@ -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
<!-- injectionpoint -->

View file

@ -1,10 +0,0 @@
---
sidebar: auto
editLink: false
---
# GMSP01 (PAL / Europe)
## List of available codes
<!-- injectionpoint -->

View file

@ -1,7 +1,8 @@
---
sidebar: auto
editLink: false
---
# Code Reference
<VersionCards />
<!-- injectionpoint -->

View file

@ -1,10 +0,0 @@
---
sidebar: auto
editLink: false
---
# GMSE01 (NTSC-U / Nord Amerika)
## Liste der verfügbaren Codes
<!-- injectionpoint -->

View file

@ -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
<!-- injectionpoint -->

View file

@ -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
<!-- injectionpoint -->

View file

@ -1,10 +0,0 @@
---
sidebar: auto
editLink: false
---
# GMSP01 (PAL / Europa)
## Liste der verfügbaren Codes
<!-- injectionpoint -->

View file

@ -1,7 +1,8 @@
---
sidebar: auto
editLink: false
---
# Code Referenz
<VersionCards />
<!-- injectionpoint -->

View file

@ -1,10 +0,0 @@
---
sidebar: auto
editLink: false
---
# GMSE01 (NTSC-U / Amérique du Nord)
## Liste des codes disponibles
<!-- injectionpoint -->

View file

@ -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
<!-- injectionpoint -->

View file

@ -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
<!-- injectionpoint -->

View file

@ -1,10 +0,0 @@
---
sidebar: auto
editLink: false
---
# GMSP01 (PAL / Europe)
## Liste des codes disponibles
<!-- injectionpoint -->

View file

@ -1,7 +1,8 @@
---
sidebar: auto
editLink: false
---
# Référence des codes
<VersionCards />
<!-- injectionpoint -->

View file

@ -1,10 +0,0 @@
---
sidebar: auto
editLink: false
---
# GMSE01 (NTSC-U / 北アメリカ)
## チートコードリスト
<!-- injectionpoint -->

View file

@ -1,17 +0,0 @@
---
sidebar: auto
editLink: false
---
# GMSJ01 (NTSC-J / 日本語)
<!-- prettier-ignore-start -->
::: tip
このページはJP1.0NTSC-J 1.0)のチートコードリストです。[JP1.1はこちら](/ja/code-reference/gmsj0a.html)
:::
## チートコードリスト
<!-- prettier-ignore-end -->
<!-- injectionpoint -->

View file

@ -1,18 +0,0 @@
---
sidebar: auto
editLink: false
---
<!-- prettier-ignore-start -->
# GMSJ01 (NTSC-J / 日本語)
::: tip
このページはJP1.1NTSC-J 1.1)のチートコードリストです。[JP1.0はこちら](/ja/code-reference/gmsj01.html)
:::
## チートコードリスト
<!-- prettier-ignore-end -->
<!-- injectionpoint -->

View file

@ -1,10 +0,0 @@
---
sidebar: auto
editLink: false
---
# GMSP01 (PAL / ヨーロッパ)
## チートコードリスト
<!-- injectionpoint -->

View file

@ -1,7 +1,8 @@
---
sidebar: auto
editLink: false
---
# チートコード一覧
<VersionCards />
<!-- injectionpoint -->