Skip to content

Commit 5f32201

Browse files
committed
Reuse parseSchemas
1 parent 5259cc4 commit 5f32201

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

react-router.config.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Config } from "@react-router/dev/config";
22
import { GAME_LIST } from "./src/games-list.ts";
3+
import { parseSchemas, type SchemasJson } from "./src/data/schemas.ts";
34

45
export default {
56
ssr: false,
@@ -18,16 +19,13 @@ export default {
1819
paths.push(`/${game.id}`);
1920

2021
const buf = readFileSync(resolve("schemas", `${game.id}.json.gz`));
21-
const data = JSON.parse(gunzipSync(buf).toString("utf-8"));
22+
const data: SchemasJson = JSON.parse(gunzipSync(buf).toString("utf-8"));
23+
const { declarations } = parseSchemas(data);
2224

2325
const names = new Map<string, Set<string>>();
24-
for (const cls of data.classes ?? []) {
25-
if (!names.has(cls.module)) names.set(cls.module, new Set());
26-
names.get(cls.module)!.add(cls.name);
27-
}
28-
for (const enm of data.enums ?? []) {
29-
if (!names.has(enm.module)) names.set(enm.module, new Set());
30-
names.get(enm.module)!.add(enm.name);
26+
for (const d of declarations) {
27+
if (!names.has(d.module)) names.set(d.module, new Set());
28+
names.get(d.module)!.add(d.name);
3129
}
3230

3331
const limit = process.env.PRERENDER_ALL ? 0 : 10;

scripts/generate-sitemap.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { gunzipSync } from "node:zlib";
33
import { resolve, dirname } from "node:path";
44
import { fileURLToPath } from "node:url";
55
import { GAME_LIST, SITE_ORIGIN } from "../src/games-list.ts";
6+
import { parseSchemas, type SchemasJson } from "../src/data/schemas.ts";
67

78
const __dirname = dirname(fileURLToPath(import.meta.url));
89
const schemasDir = resolve(__dirname, "../schemas");
@@ -47,20 +48,19 @@ const indexEntries: { file: string; lastmod?: string }[] = [];
4748

4849
for (const game of GAME_LIST) {
4950
const buf = readFileSync(resolve(schemasDir, `${game.id}.json.gz`));
50-
const data = JSON.parse(gunzipSync(buf).toString("utf-8"));
51+
const data: SchemasJson = JSON.parse(gunzipSync(buf).toString("utf-8"));
52+
const { declarations, metadata } = parseSchemas(data);
5153

52-
const isoDate = data.version_date ? toIsoDate(data.version_date, data.version_time) : undefined;
54+
const isoDate = metadata.versionDate
55+
? toIsoDate(metadata.versionDate, metadata.versionTime)
56+
: undefined;
5357

5458
mainUrls.push({ loc: `${SITE_ORIGIN}${basePath}/${game.id}`, lastmod: isoDate });
5559

5660
const byModule = new Map<string, string[]>();
57-
for (const cls of data.classes ?? []) {
58-
if (!byModule.has(cls.module)) byModule.set(cls.module, []);
59-
byModule.get(cls.module)!.push(cls.name);
60-
}
61-
for (const enm of data.enums ?? []) {
62-
if (!byModule.has(enm.module)) byModule.set(enm.module, []);
63-
byModule.get(enm.module)!.push(enm.name);
61+
for (const d of declarations) {
62+
if (!byModule.has(d.module)) byModule.set(d.module, []);
63+
byModule.get(d.module)!.push(d.name);
6464
}
6565

6666
for (const mod of byModule.keys()) {
@@ -70,10 +70,7 @@ for (const game of GAME_LIST) {
7070
// Per-game sitemap: all declarations
7171
const gameUrls: SitemapUrl[] = [];
7272
for (const [mod, names] of byModule) {
73-
const seen = new Set<string>();
7473
for (const name of names) {
75-
if (seen.has(name)) continue;
76-
seen.add(name);
7774
gameUrls.push({
7875
loc: `${SITE_ORIGIN}${basePath}/${game.id}/${mod}/${name}`,
7976
});

0 commit comments

Comments
 (0)