Skip to content

Commit db05cbf

Browse files
committed
fix: add fallback if metadata JSON file does not exist
1 parent f9bfac9 commit db05cbf

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

website/typst-docs-web/src/metadata.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import metadataJson from "../public/metadata.json";
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
4+
const METADATA_FILE = path.resolve(process.cwd(), "./public/metadata.json");
25

36
type Metadata = {
47
language: "ja-JP" | "en-US";
@@ -13,7 +16,25 @@ type Metadata = {
1316
displayTranslationStatus: boolean;
1417
};
1518

16-
const metadata = metadataJson as Metadata;
19+
const metadata: Metadata = (() => {
20+
if (fs.existsSync(METADATA_FILE)) {
21+
const content = fs.readFileSync(METADATA_FILE, "utf-8");
22+
return JSON.parse(content);
23+
}
24+
// If metadata JSON file does not exist, fallback for test environments
25+
return {
26+
language: "en-US",
27+
version: "0.0.0",
28+
typstOfficialUrl: "https://typst.app/",
29+
typstOfficialDocsUrl: "https://typst.app/docs/",
30+
githubOrganizationUrl: "https://github.com/typst",
31+
githubRepositoryUrl: "https://github.com/typst/typst",
32+
discordServerUrl: "https://discord.gg/dummy",
33+
originUrl: "https://example.com/",
34+
basePath: "/docs/",
35+
displayTranslationStatus: true,
36+
} satisfies Metadata;
37+
})();
1738

1839
/** The language of the documentation. */
1940
export const language = metadata.language;

0 commit comments

Comments
 (0)