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
36type 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. */
1940export const language = metadata . language ;
0 commit comments