Skip to content

Commit

Permalink
The i18n route generator works now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Southpaw1496 committed Aug 29, 2024
1 parent 64f2b65 commit eec3111
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions scripts/preprocess.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import teamData from "../src/data/TeamData.mjs";
import * as paths from "./paths.mjs";
import { sortBy, tryToRunPromiseWithTimeout, NIL_DATE, linkIssues } from "./util.mjs";
import fetch from "node-fetch";
import {glob} from "glob";
import { glob } from "glob";

async function main() {
prepareCacheDirectory();
Expand Down Expand Up @@ -52,33 +52,33 @@ function generateRedirectFunctions() {

const pathPrefix = paths.SOURCE_LOCATION + "en";

glob(paths.SOURCE_LOCATION + "en/**/*.md?(x)", function (_, files) {
files.forEach((file) => {
file = file.slice(pathPrefix.length)
.split(".")
.slice(0, -1)
.join(".");

const availableLanguages = [];
allLanguages.forEach((language) => {
var files = glob.sync(paths.SOURCE_LOCATION + "en/**/*.md?(x)")
files.forEach((file) => {
file = file.slice(pathPrefix.length -1)
.split(".")
.slice(0, -1)
.join(".");

const availableLanguages = [];
allLanguages.forEach((language) => {
try {
fs.statSync(paths.SOURCE_LOCATION + language + file + ".md")
availableLanguages.push(language)
} catch {
try {
fs.statSync(paths.SOURCE_LOCATION + language + file + ".md")
fs.statSync(paths.SOURCE_LOCATION + language + file + ".mdx")
availableLanguages.push(language)
} catch {
try {
fs.statSync(paths.SOURCE_LOCATION + language + file + ".mdx")
availableLanguages.push(language)
} catch {}
}
})
} catch { }
}
})

const functionLocation = paths.FUNCTION_LOCATION + file + ".js";
const parentFolder = functionLocation.split("/").slice(0, -1).join("/");
const functionLocation = paths.FUNCTION_LOCATION + "/" + file + ".js";
const parentFolder = functionLocation.split("/").slice(0, -1).join("/");

fs.mkdirSync(parentFolder, { recursive: true });
const content = `const al = [${availableLanguages.map(l => '"' + l + '"').join(", ")}]\n${functionSource}`;
fs.writeFile(functionLocation, content, () => null);
})
fs.mkdirSync(parentFolder, { recursive: true });
const content = `const al = [${availableLanguages.map(l => '"' + l + '"').join(", ")}]\n${functionSource}`;
fs.writeFile(functionLocation, content, () => null);
return
})
}

Expand Down

1 comment on commit eec3111

@Cozy-GitHub
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See preview on Cloudflare Pages: https://b9db5658.quiltmc-org.pages.dev

Please sign in to comment.