Skip to content

Commit 00f2f99

Browse files
committed
chore: migrate metadata to use values from JSON file
1 parent faa41bb commit 00f2f99

File tree

3 files changed

+53
-17
lines changed

3 files changed

+53
-17
lines changed

website/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"private": true,
3-
"version": "0.13.1",
43
"type": "module",
54
"scripts": {
65
"dev": "vite dev",

website/src/metadata.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1-
import { version } from "../package.json";
1+
import metadataJson from "../metadata.json";
22

3-
// TODO: The metadata will be configurable via a JSON configuration file.
3+
type Metadata = {
4+
language: "ja-JP" | "en-US";
5+
version: string;
6+
typstOfficialUrl: string;
7+
typstOfficialDocsUrl: `http://${string}/` | `https://${string}/`;
8+
githubOrganizationUrl: string;
9+
githubRepositoryUrl: string;
10+
discordServerUrl: string;
11+
originUrl: string;
12+
basePath: "/" | `/${string}/`;
13+
displayTranslationStatus: boolean;
14+
};
15+
16+
const metadata = metadataJson as unknown as Metadata;
17+
18+
/** The language of the documentation. */
19+
export const language = metadata.language;
420
/** The version of the documentation, without a leading `v`. */
5-
export { version };
21+
export const version = metadata.version;
622
/** The official Typst website URL. */
7-
export const typstOfficialUrl = "https://typst.app";
23+
export const typstOfficialUrl = metadata.typstOfficialUrl;
824
/** The official Typst documentation base URL. */
9-
export const typstOfficialDocsUrl: `http://${string}/` | `https://${string}/` =
10-
"https://typst.app/docs/";
25+
export const typstOfficialDocsUrl = metadata.typstOfficialDocsUrl;
1126
/** The GitHub organization URL. */
12-
export const githubOrganizationUrl = "https://github.com/typst-jp";
27+
export const githubOrganizationUrl = metadata.githubOrganizationUrl;
1328
/** The GitHub repository URL. */
14-
export const githubRepositoryUrl = "https://github.com/typst-jp/docs";
29+
export const githubRepositoryUrl = metadata.githubRepositoryUrl;
1530
/** The Discord server invite URL. */
16-
export const discordServerUrl = "https://discord.gg/9xF7k4aAuH";
31+
export const discordServerUrl = metadata.discordServerUrl;
1732
/** The origin URL of the deployed site, used for metadata. Note that the base path should not be included. */
18-
export const originUrl = "https://typst-jp.github.io/";
33+
export const originUrl = metadata.originUrl;
1934
/** The base public path for deployment. This must match the value used in typst-docs. */
20-
export const basePath: "/" | `/${string}/` = "/docs/";
35+
export const basePath = metadata.basePath;
2136
/** Indicates whether to display the translation status on the site. Community content is always displayed. */
22-
export const displayTranslationStatus: boolean = true;
37+
export const displayTranslationStatus = metadata.displayTranslationStatus;

website/src/translation/index.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import type { FC } from "hono/jsx";
22
import type { TooltipProps } from "../components/ui/Tooltip";
3+
import { language } from "../metadata";
4+
import {
5+
Translation as EnUSTranslation,
6+
translation as enUSTranslation,
7+
} from "./en-US";
8+
import {
9+
Translation as JaJPTranslation,
10+
translation as jaJPTranslation,
11+
} from "./ja-JP";
312

413
/**
514
* Translation dictionary for UI attributes and aria labels.
@@ -80,7 +89,20 @@ export type TranslationComponentProps =
8089
*/
8190
export type TranslationComponent = FC<TranslationComponentProps>;
8291

83-
/**
84-
* Switch translation language here.
85-
*/
86-
export { Translation, translation } from "./ja-JP";
92+
// Switch translation language.
93+
let Translation: TranslationComponent;
94+
let translation: TranslationObject;
95+
96+
switch (language) {
97+
case "ja-JP":
98+
Translation = JaJPTranslation;
99+
translation = jaJPTranslation;
100+
break;
101+
case "en-US":
102+
Translation = EnUSTranslation;
103+
translation = enUSTranslation;
104+
break;
105+
default:
106+
throw new Error(`Unsupported language: ${language}`);
107+
}
108+
export { Translation, translation };

0 commit comments

Comments
 (0)