Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions netlify-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env bash
set -euxo pipefail

# 1. Install tools and dependencies

curl https://mise.run | sh
mise trust
mise install
mise exec -- bun install --frozen-lockfile

# 2. Prepare common files

mkdir _site

# Prepare favicon
curl -L https://github.com/typst-community/org/raw/main/design/typst-community.icon.png \
-o _site/favicon.png
cp _site/favicon.png public/favicon.png

# Prepare the index page
REF=$(git rev-parse --short HEAD)
DATE=$(git log --max-count=1 --pretty='%cd' --date=iso)
cat << EOF > _site/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>typst-docs-web</title>
<style>
body {
display: grid;
place-items: center;
min-height: 100vh;
background: #eff0f3;
}

body > main {
padding: 2em;
border-radius: 1em;
box-shadow: 0 0 1em #ccc;
background: white;
color: #565565;

li {
margin-block: 0.5em;
}
}
</style>
</head>
<body>
<main>
<h1><a href="https://github.com/typst-community/typst-docs-web/">typst-docs-web</a></h1>
<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>
<p>This website is for developing typst-docs-web. Its contents might be changed at anytime.</p>
<ul>
<li><a href="./en-US-v0.14.0/">en-US, v0.14.0</a></li>
<li><a href="./en-US-v0.13.1/">en-US, v0.13.1</a></li>
<li><a href="./ja-JP/">ja-JP, v0.13.1</a></li>
</ul>
<p>
typst-docs-web version:
<a href="https://github.com/typst-community/typst-docs-web/tree/$REF"><code>$REF</code> ($DATE)</a>
</p>
</main>
</body>
</html>
EOF

# 3. Build
# 3.1. Build en-US

build_en_US() {
local VERSION="$1"

BASE="en-US-$VERSION"

# Prepare docs.json
curl -L https://github.com/typst-community/dev-builds/releases/download/docs-"$VERSION"/docs.json \
-o public/docs.json
sd '/DOCS-BASE/' "/$BASE/" public/docs.json

# Prepare docs assets
curl -LO https://github.com/typst-community/dev-builds/releases/download/docs-"$VERSION"/docs-assets.zip
unzip docs-assets.zip && rm docs-assets.zip
mv assets public/assets

# Configure metadata
cat << EOF > public/metadata.json
{
"\$schema": "../metadata.schema.json",
"language": "en-US",
"version": "${VERSION#v}",
"typstOfficialUrl": "https://typst.app",
"typstOfficialDocsUrl": "https://typst.app/docs/",
"githubOrganizationUrl": "https://github.com/typst-community",
"githubRepositoryUrl": "https://github.com/typst-community/typst-docs-web",
"discordServerUrl": "https://discord.gg/2uDybryKPe",
"originUrl": "${DEPLOY_URL:-https://example.com}/",
"basePath": "/$BASE/",
"displayTranslationStatus": false
}
EOF
# $DEPLOY_URL will be set by netlify. Fallback to example.com for local testing.
# https://docs.netlify.com/build/configure-builds/environment-variables/#deploy-urls-and-metadata

# Build
mise exec -- bun run build
mv dist _site/"$BASE"

# Clean
rm -r public/{docs.json,assets,metadata.json}
}

build_en_US v0.14.0
build_en_US v0.13.1

# 3.2. Build ja-JP

# Prepare JSON files
mise exec -- bun run fetch-docs-ja-jp
sd '"/docs/' '"/ja-JP/' public/docs.json
sd --fixed-strings \
'"basePath": "/docs/",' \
'"basePath": "/ja-JP/",' \
public/metadata.json

# Prepare docs assets
# At present, typst-jp do not translate comments within example code.
# And there is no simple way to download assets from GitHub Actions or the gh-pages branch.
# Therefore, we reuse the assets from the official version.
curl -LO https://github.com/typst-community/dev-builds/releases/download/docs-v0.13.1/docs-assets.zip
unzip docs-assets.zip && rm docs-assets.zip
mv assets public/assets

# Build
mise exec -- bun run build
mv dist _site/ja-JP

# Clean
rm -r public/{docs,metadata,translation-status}.json public/assets
3 changes: 3 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
command = "bash netlify-build.sh"
publish = "_site"