Skip to content

Commit d43f4ab

Browse files
3w36zj6CopilotYDX-2147483647
authored
chore: add metadata JSON file for website configuration (typst-jp#303)
Co-authored-by: Copilot <[email protected]> Co-authored-by: Y.D.X. <[email protected]>
1 parent 18f7590 commit d43f4ab

File tree

5 files changed

+127
-17
lines changed

5 files changed

+127
-17
lines changed

website/metadata.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$schema": "./metadata.schema.json",
3+
"language": "ja-JP",
4+
"version": "0.13.1",
5+
"typstOfficialUrl": "https://typst.app",
6+
"typstOfficialDocsUrl": "https://typst.app/docs/",
7+
"githubOrganizationUrl": "https://github.com/typst-jp",
8+
"githubRepositoryUrl": "https://github.com/typst-jp/docs",
9+
"discordServerUrl": "https://discord.gg/9xF7k4aAuH",
10+
"originUrl": "https://typst-jp.github.io/",
11+
"basePath": "/docs/",
12+
"displayTranslationStatus": true
13+
}

website/metadata.schema.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"properties": {
5+
"language": {
6+
"type": "string",
7+
"description": "The language of the documentation.",
8+
"enum": ["ja-JP", "en-US"]
9+
},
10+
"version": {
11+
"type": "string",
12+
"description": "The version of the documentation, without a leading 'v'."
13+
},
14+
"typstOfficialUrl": {
15+
"type": "string",
16+
"format": "uri",
17+
"description": "The official Typst website URL."
18+
},
19+
"typstOfficialDocsUrl": {
20+
"type": "string",
21+
"description": "The official Typst documentation base URL.",
22+
"pattern": "^https?://.+/$"
23+
},
24+
"githubOrganizationUrl": {
25+
"type": "string",
26+
"format": "uri",
27+
"description": "The GitHub organization URL."
28+
},
29+
"githubRepositoryUrl": {
30+
"type": "string",
31+
"format": "uri",
32+
"description": "The GitHub repository URL."
33+
},
34+
"discordServerUrl": {
35+
"type": "string",
36+
"format": "uri",
37+
"description": "The Discord server invite URL."
38+
},
39+
"originUrl": {
40+
"type": "string",
41+
"format": "uri",
42+
"description": "The origin URL of the deployed site, used for metadata. Note that the base path should not be included."
43+
},
44+
"basePath": {
45+
"type": "string",
46+
"description": "The base public path for deployment. This must match the value used in typst-docs.",
47+
"pattern": "^/([^/]+/)*$"
48+
},
49+
"displayTranslationStatus": {
50+
"type": "boolean",
51+
"description": "Indicates whether to display the translation status on the site. Community content is always displayed."
52+
}
53+
},
54+
"required": [
55+
"language",
56+
"version",
57+
"typstOfficialUrl",
58+
"typstOfficialDocsUrl",
59+
"githubOrganizationUrl",
60+
"githubRepositoryUrl",
61+
"discordServerUrl",
62+
"originUrl",
63+
"basePath",
64+
"displayTranslationStatus"
65+
]
66+
}

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 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: 21 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,15 @@ 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+
const { Translation, translation } = (() => {
94+
switch (language) {
95+
case "ja-JP":
96+
return { Translation: JaJPTranslation, translation: jaJPTranslation };
97+
case "en-US":
98+
return { Translation: EnUSTranslation, translation: enUSTranslation };
99+
default:
100+
throw new Error(`Unsupported language: ${language}`);
101+
}
102+
})();
103+
export { Translation, translation };

0 commit comments

Comments
 (0)