diff --git a/website/metadata.json b/website/metadata.json new file mode 100644 index 0000000000..79b82f0968 --- /dev/null +++ b/website/metadata.json @@ -0,0 +1,13 @@ +{ + "$schema": "./metadata.schema.json", + "language": "ja-JP", + "version": "0.13.1", + "typstOfficialUrl": "https://typst.app", + "typstOfficialDocsUrl": "https://typst.app/docs/", + "githubOrganizationUrl": "https://github.com/typst-jp", + "githubRepositoryUrl": "https://github.com/typst-jp/docs", + "discordServerUrl": "https://discord.gg/9xF7k4aAuH", + "originUrl": "https://typst-jp.github.io/", + "basePath": "/docs/", + "displayTranslationStatus": true +} diff --git a/website/metadata.schema.json b/website/metadata.schema.json new file mode 100644 index 0000000000..fa06693724 --- /dev/null +++ b/website/metadata.schema.json @@ -0,0 +1,66 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "language": { + "type": "string", + "description": "The language of the documentation.", + "enum": ["ja-JP", "en-US"] + }, + "version": { + "type": "string", + "description": "The version of the documentation, without a leading 'v'." + }, + "typstOfficialUrl": { + "type": "string", + "format": "uri", + "description": "The official Typst website URL." + }, + "typstOfficialDocsUrl": { + "type": "string", + "description": "The official Typst documentation base URL.", + "pattern": "^https?://.+/$" + }, + "githubOrganizationUrl": { + "type": "string", + "format": "uri", + "description": "The GitHub organization URL." + }, + "githubRepositoryUrl": { + "type": "string", + "format": "uri", + "description": "The GitHub repository URL." + }, + "discordServerUrl": { + "type": "string", + "format": "uri", + "description": "The Discord server invite URL." + }, + "originUrl": { + "type": "string", + "format": "uri", + "description": "The origin URL of the deployed site, used for metadata. Note that the base path should not be included." + }, + "basePath": { + "type": "string", + "description": "The base public path for deployment. This must match the value used in typst-docs.", + "pattern": "^/([^/]+/)*$" + }, + "displayTranslationStatus": { + "type": "boolean", + "description": "Indicates whether to display the translation status on the site. Community content is always displayed." + } + }, + "required": [ + "language", + "version", + "typstOfficialUrl", + "typstOfficialDocsUrl", + "githubOrganizationUrl", + "githubRepositoryUrl", + "discordServerUrl", + "originUrl", + "basePath", + "displayTranslationStatus" + ] +} diff --git a/website/package.json b/website/package.json index be3a308670..136a3fed33 100644 --- a/website/package.json +++ b/website/package.json @@ -1,6 +1,5 @@ { "private": true, - "version": "0.13.1", "type": "module", "scripts": { "dev": "vite dev", diff --git a/website/src/metadata.ts b/website/src/metadata.ts index ccff0c857d..6cb22ee9cb 100644 --- a/website/src/metadata.ts +++ b/website/src/metadata.ts @@ -1,22 +1,37 @@ -import { version } from "../package.json"; +import metadataJson from "../metadata.json"; -// TODO: The metadata will be configurable via a JSON configuration file. +type Metadata = { + language: "ja-JP" | "en-US"; + version: string; + typstOfficialUrl: string; + typstOfficialDocsUrl: `http://${string}/` | `https://${string}/`; + githubOrganizationUrl: string; + githubRepositoryUrl: string; + discordServerUrl: string; + originUrl: string; + basePath: "/" | `/${string}/`; + displayTranslationStatus: boolean; +}; + +const metadata = metadataJson as Metadata; + +/** The language of the documentation. */ +export const language = metadata.language; /** The version of the documentation, without a leading `v`. */ -export { version }; +export const version = metadata.version; /** The official Typst website URL. */ -export const typstOfficialUrl = "https://typst.app"; +export const typstOfficialUrl = metadata.typstOfficialUrl; /** The official Typst documentation base URL. */ -export const typstOfficialDocsUrl: `http://${string}/` | `https://${string}/` = - "https://typst.app/docs/"; +export const typstOfficialDocsUrl = metadata.typstOfficialDocsUrl; /** The GitHub organization URL. */ -export const githubOrganizationUrl = "https://github.com/typst-jp"; +export const githubOrganizationUrl = metadata.githubOrganizationUrl; /** The GitHub repository URL. */ -export const githubRepositoryUrl = "https://github.com/typst-jp/docs"; +export const githubRepositoryUrl = metadata.githubRepositoryUrl; /** The Discord server invite URL. */ -export const discordServerUrl = "https://discord.gg/9xF7k4aAuH"; +export const discordServerUrl = metadata.discordServerUrl; /** The origin URL of the deployed site, used for metadata. Note that the base path should not be included. */ -export const originUrl = "https://typst-jp.github.io/"; +export const originUrl = metadata.originUrl; /** The base public path for deployment. This must match the value used in typst-docs. */ -export const basePath: "/" | `/${string}/` = "/docs/"; +export const basePath = metadata.basePath; /** Indicates whether to display the translation status on the site. Community content is always displayed. */ -export const displayTranslationStatus: boolean = true; +export const displayTranslationStatus = metadata.displayTranslationStatus; diff --git a/website/src/translation/index.tsx b/website/src/translation/index.tsx index 375fe759f6..62fc10bb72 100644 --- a/website/src/translation/index.tsx +++ b/website/src/translation/index.tsx @@ -1,5 +1,14 @@ import type { FC } from "hono/jsx"; import type { TooltipProps } from "../components/ui/Tooltip"; +import { language } from "../metadata"; +import { + Translation as EnUSTranslation, + translation as enUSTranslation, +} from "./en-US"; +import { + Translation as JaJPTranslation, + translation as jaJPTranslation, +} from "./ja-JP"; /** * Translation dictionary for UI attributes and aria labels. @@ -80,7 +89,15 @@ export type TranslationComponentProps = */ export type TranslationComponent = FC; -/** - * Switch translation language here. - */ -export { Translation, translation } from "./ja-JP"; +// Switch translation language. +const { Translation, translation } = (() => { + switch (language) { + case "ja-JP": + return { Translation: JaJPTranslation, translation: jaJPTranslation }; + case "en-US": + return { Translation: EnUSTranslation, translation: enUSTranslation }; + default: + throw new Error(`Unsupported language: ${language}`); + } +})(); +export { Translation, translation };