Repository navigation
Expand file tree
/
Copy pathreact-router.config.ts
More file actions
70 lines (57 loc) · 2.41 KB
/
Copy pathreact-router.config.ts
File metadata and controls
70 lines (57 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { readFile } from "node:fs/promises";
import type { Config } from "@react-router/dev/config";
import { GAME_LIST } from "./src/games-list.ts";
import { parseSchemas, type SchemasJson } from "./src/data/schemas.ts";
const isDev = process.argv.includes("dev");
export default {
ssr: false,
appDirectory: "src",
basename: "/SchemaExplorer/",
prerender: isDev
? false
: {
concurrency: 8,
async paths({ getStaticPaths }) {
const paths = [...getStaticPaths(), "/"];
for (const game of GAME_LIST) {
paths.push(`/${game.id}`);
const data: SchemasJson = JSON.parse(
await readFile(`schemas/${game.id}.json`, "utf-8"),
);
const { declarations, consoleItems, entities } = parseSchemas(data);
if (consoleItems.length > 0) paths.push(`/${game.id}/convars`);
const limit = process.env.PRERENDER_ALL ? 0 : 10;
let count = 0;
for (const [mod, moduleMap] of declarations) {
paths.push(`/${game.id}/${mod}`);
if (!limit || count < limit) {
for (const name of moduleMap.keys()) {
if (process.platform === "win32" && name.includes("::")) continue;
paths.push(`/${game.id}/${mod}/${name}`);
if (limit && ++count >= limit) break;
}
}
}
// The browser redirects design name links like /cs2/logic_relay. A page of their own
// gives link previews the entity's title and description
const designNames = new Set<string>();
for (const entity of entities) {
const { designName } = entity;
if (!designName || declarations.has(designName)) continue;
if (!declarations.get(entity.classModule)?.has(entity.class)) continue;
if (process.platform === "win32" && /[<>:"|?*]/.test(designName)) continue;
designNames.add(designName);
}
for (const designName of [...designNames].slice(0, limit || undefined)) {
paths.push(`/${game.id}/${designName}`);
}
if (limit) {
console.log(
`Prerender limited to ${limit} pages per game, set PRERENDER_ALL=1 to generate all pages`,
);
}
}
return paths;
},
},
} satisfies Config;