| 
 | 1 | +#!/usr/bin/env bash  | 
 | 2 | +set -euxo pipefail  | 
 | 3 | + | 
 | 4 | +# 1. Install tools and dependencies  | 
 | 5 | + | 
 | 6 | +curl https://mise.run | sh  | 
 | 7 | +mise trust  | 
 | 8 | +mise install  | 
 | 9 | +mise exec -- bun install --frozen-lockfile  | 
 | 10 | + | 
 | 11 | +# 2. Prepare common files  | 
 | 12 | + | 
 | 13 | +mkdir _site  | 
 | 14 | + | 
 | 15 | +# Prepare favicon  | 
 | 16 | +curl -L https://github.com/typst-community/org/raw/main/design/typst-community.icon.png \  | 
 | 17 | +  -o _site/favicon.png  | 
 | 18 | +cp _site/favicon.png public/favicon.png  | 
 | 19 | + | 
 | 20 | +# Prepare the index page  | 
 | 21 | +REF=$(git rev-parse --short HEAD)  | 
 | 22 | +DATE=$(git log --max-count=1 --pretty='%cd' --date=iso)  | 
 | 23 | +cat << EOF > _site/index.html  | 
 | 24 | +<!DOCTYPE html>  | 
 | 25 | +<html lang="en">  | 
 | 26 | +  <head>  | 
 | 27 | +    <meta charset="utf-8">  | 
 | 28 | +    <meta name="viewport" content="width=device-width, initial-scale=1">  | 
 | 29 | +    <title>typst-docs-web</title>  | 
 | 30 | +    <style>  | 
 | 31 | +      body {  | 
 | 32 | +        display: grid;  | 
 | 33 | +        place-items: center;  | 
 | 34 | +        min-height: 100vh;  | 
 | 35 | +        background: #eff0f3;  | 
 | 36 | +      }  | 
 | 37 | +
  | 
 | 38 | +      body > main {  | 
 | 39 | +        padding: 2em;  | 
 | 40 | +        border-radius: 1em;  | 
 | 41 | +        box-shadow: 0 0 1em #ccc;  | 
 | 42 | +        background: white;  | 
 | 43 | +        color: #565565;  | 
 | 44 | +
  | 
 | 45 | +        li {  | 
 | 46 | +          margin-block: 0.5em;  | 
 | 47 | +        }  | 
 | 48 | +      }  | 
 | 49 | +    </style>  | 
 | 50 | +  </head>  | 
 | 51 | +  <body>  | 
 | 52 | +    <main>  | 
 | 53 | +      <h1><a href="https://github.com/typst-community/typst-docs-web/">typst-docs-web</a></h1>  | 
 | 54 | +      <p>Build a website from the documentation JSON file generated by <a href="https://github.com/typst/typst/blob/main/docs/Cargo.toml#L2">typst-docs</a>.</p>  | 
 | 55 | +      <p>This website is for developing typst-docs-web. Its contents might be changed at anytime.</p>  | 
 | 56 | +      <ul>  | 
 | 57 | +        <li><a href="./en-US-v0.14.0/">en-US, v0.14.0</a></li>  | 
 | 58 | +        <li><a href="./en-US-v0.13.1/">en-US, v0.13.1</a></li>  | 
 | 59 | +        <li><a href="./ja-JP/">ja-JP, v0.13.1</a></li>  | 
 | 60 | +      </ul>  | 
 | 61 | +      <p>  | 
 | 62 | +        typst-docs-web version:  | 
 | 63 | +        <a href="https://github.com/typst-community/typst-docs-web/tree/$REF"><code>$REF</code> ($DATE)</a>  | 
 | 64 | +      </p>  | 
 | 65 | +    </main>  | 
 | 66 | +  </body>  | 
 | 67 | +</html>  | 
 | 68 | +EOF  | 
 | 69 | + | 
 | 70 | +# 3. Build  | 
 | 71 | +# 3.1. Build en-US  | 
 | 72 | + | 
 | 73 | +build_en_US() {  | 
 | 74 | +  local VERSION="$1"  | 
 | 75 | + | 
 | 76 | +  BASE="en-US-$VERSION"  | 
 | 77 | + | 
 | 78 | +  # Prepare docs.json  | 
 | 79 | +  curl -L https://github.com/typst-community/dev-builds/releases/download/docs-"$VERSION"/docs.json \  | 
 | 80 | +    -o public/docs.json  | 
 | 81 | +  sd '/DOCS-BASE/' "/$BASE/" public/docs.json  | 
 | 82 | + | 
 | 83 | +  # Prepare docs assets  | 
 | 84 | +  curl -LO https://github.com/typst-community/dev-builds/releases/download/docs-"$VERSION"/docs-assets.zip  | 
 | 85 | +  unzip docs-assets.zip && rm docs-assets.zip  | 
 | 86 | +  mv assets public/assets  | 
 | 87 | + | 
 | 88 | +  # Configure metadata  | 
 | 89 | +  cat << EOF > public/metadata.json  | 
 | 90 | +{  | 
 | 91 | +  "\$schema": "../metadata.schema.json",  | 
 | 92 | +  "language": "en-US",  | 
 | 93 | +  "version": "${VERSION#v}",  | 
 | 94 | +  "typstOfficialUrl": "https://typst.app",  | 
 | 95 | +  "typstOfficialDocsUrl": "https://typst.app/docs/",  | 
 | 96 | +  "githubOrganizationUrl": "https://github.com/typst-community",  | 
 | 97 | +  "githubRepositoryUrl": "https://github.com/typst-community/typst-docs-web",  | 
 | 98 | +  "discordServerUrl": "https://discord.gg/2uDybryKPe",  | 
 | 99 | +  "originUrl": "${DEPLOY_URL:-https://example.com}/",  | 
 | 100 | +  "basePath": "/$BASE/",  | 
 | 101 | +  "displayTranslationStatus": false  | 
 | 102 | +}  | 
 | 103 | +EOF  | 
 | 104 | +  # $DEPLOY_URL will be set by netlify. Fallback to example.com for local testing.  | 
 | 105 | +  # https://docs.netlify.com/build/configure-builds/environment-variables/#deploy-urls-and-metadata  | 
 | 106 | + | 
 | 107 | +  # Build  | 
 | 108 | +  mise exec -- bun run build  | 
 | 109 | +  mv dist _site/"$BASE"  | 
 | 110 | + | 
 | 111 | +  # Clean  | 
 | 112 | +  rm -r public/{docs.json,assets,metadata.json}  | 
 | 113 | +}  | 
 | 114 | + | 
 | 115 | +build_en_US v0.14.0  | 
 | 116 | +build_en_US v0.13.1  | 
 | 117 | + | 
 | 118 | +# 3.2. Build ja-JP  | 
 | 119 | + | 
 | 120 | +# Prepare JSON files  | 
 | 121 | +mise exec -- bun run fetch-docs-ja-jp  | 
 | 122 | +sd '"/docs/' '"/ja-JP/' public/docs.json  | 
 | 123 | +sd --fixed-strings \  | 
 | 124 | +  '"basePath": "/docs/",' \  | 
 | 125 | +  '"basePath": "/ja-JP/",' \  | 
 | 126 | +  public/metadata.json  | 
 | 127 | + | 
 | 128 | +# Prepare docs assets  | 
 | 129 | +# At present, typst-jp do not translate comments within example code.  | 
 | 130 | +# And there is no simple way to download assets from GitHub Actions or the gh-pages branch.  | 
 | 131 | +# Therefore, we reuse the assets from the official version.  | 
 | 132 | +curl -LO https://github.com/typst-community/dev-builds/releases/download/docs-v0.13.1/docs-assets.zip  | 
 | 133 | +unzip docs-assets.zip && rm docs-assets.zip  | 
 | 134 | +mv assets public/assets  | 
 | 135 | + | 
 | 136 | +# Build  | 
 | 137 | +mise exec -- bun run build  | 
 | 138 | +mv dist _site/ja-JP  | 
 | 139 | + | 
 | 140 | +# Clean  | 
 | 141 | +rm -r public/{docs,metadata,translation-status}.json public/assets  | 
0 commit comments