- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13
chore: add metadata JSON file for website configuration #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
74e3710    to
    00f2f99      
    Compare
  
    Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a centralized metadata configuration system for the website, replacing hardcoded values with a JSON-based configuration approach. The changes enable easier configuration for different languages and deployments by consolidating site-wide settings into a single metadata file.
- Replaces hardcoded metadata values with a JSON configuration file and TypeScript schema
- Implements dynamic language switching based on metadata configuration
- Removes version from package.json in favor of metadata-driven versioning
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description | 
|---|---|
| website/src/translation/index.tsx | Updates translation system to dynamically select language based on metadata configuration | 
| website/src/metadata.ts | Refactors to load all metadata from JSON file instead of hardcoded values | 
| website/package.json | Removes version field, now managed through metadata.json | 
| website/metadata.schema.json | Adds JSON schema for metadata validation | 
| website/metadata.json | Introduces centralized configuration file with all site metadata | 
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| Could you please do a quick review? @YDX-2147483647 @Its-Just-Nans | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's good
Another options would be to use an array destructuring, but the order will be important
const [Translation, translation] = (() => {
  switch (language) {
    case "ja-JP":
      return [JaJPTranslation, jaJPTranslation];
    case "en-US":
      return [EnUSTranslation, enUSTranslation];
    default:
      throw new Error(`Unsupported language: ${language}`);
  }
})();        
          
                website/src/metadata.ts
              
                Outdated
          
        
      | displayTranslationStatus: boolean; | ||
| }; | ||
|  | ||
| const metadata = metadataJson as unknown as Metadata; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as unknown is not necessary here.
Additionally, I remove it and find displayTranslationStatus is missing in metadata.json. 😸
        
          
                website/metadata.schema.json
              
                Outdated
          
        
      | "basePath": { | ||
| "type": "string", | ||
| "description": "The base public path for deployment. This must match the value used in typst-docs.", | ||
| "pattern": "^/$|^/[^/]+/$" | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think [^/]+ should be replaced with .+. Otherwise, it won't allow /foo/bar/.
| throw new Error(`Unsupported language: ${language}`); | ||
| } | ||
| })(); | ||
| export { Translation, translation }; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If properly set up, then this can be simplified to await import(`./locales/${language}.tsx`). Not sure if it's worth it, though.
https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars
Properly set up:
- 
Enable top-level awaitfor TypeScript.Add "target": "es2017"(or newer) towebsite/tsconfig.json
- 
Enable dynamic import for Vite. - Add a new dependency @rollup/plugin-dynamic-import-vars
- Add dynamicImportVars({ include: "src/translation/", errorWhenNoFilesFound: true })(or maybe justdynamicImportVars()) todefineConfig(plugins: [...])inwebsite/vite.config.ts
 
- Add a new dependency 
- 
Mitigate limitations. - 
Put {ja-JP,en-US}.tsxinto a dedicated directory, because variable imports cannot import their own directory.
- 
Annotate { Translation: TranslationComponent; translation: TranslationObject }, because it's too hard for typescript to infer the type.
 
- 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
The comments are for reference only and can be ignored.
Co-authored-by: Y.D.X. <[email protected]>
Continues typst-jp#303. Relates to typst-jp#233.
[`vars` can also be read in as a file. (mise.jdx.dev)](https://mise.jdx.dev/tasks/task-configuration.html#vars-options). Continues typst-jp#303. Relates to typst-jp#233.
cf. #233
This pull request introduces a metadata configuration system for the website, centralizing site-wide settings into a new JSON file and schema. It refactors how metadata and translation settings are loaded, making the site easier to configure for different languages and deployments.