- 
                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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      faa41bb
              
                chore: add metadata JSON file for website configuration
              
              
                3w36zj6 00f2f99
              
                chore: migrate metadata to use values from JSON file
              
              
                3w36zj6 95121ba
              
                Update website/metadata.json
              
              
                3w36zj6 0e7b6c0
              
                Update website/metadata.json
              
              
                3w36zj6 69e3ccb
              
                Update website/metadata.json
              
              
                3w36zj6 cdb4c9f
              
                Update website/src/translation/index.tsx
              
              
                3w36zj6 94fc303
              
                fix: apply suggestions
              
              
                3w36zj6 f9af723
              
                Update website/metadata.schema.json
              
              
                3w36zj6 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -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 | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -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" | ||
| ] | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| { | ||
| "private": true, | ||
| "version": "0.13.1", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite dev", | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -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; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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.jsonEnable dynamic import for Vite.
@rollup/plugin-dynamic-import-varsdynamicImportVars({ include: "src/translation/", errorWhenNoFilesFound: true })(or maybe justdynamicImportVars()) todefineConfig(plugins: [...])inwebsite/vite.config.tsMitigate 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.