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