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
62 changes: 22 additions & 40 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ jobs:
- name: ${{ matrix.name }}
run: ${{ matrix.command }}

ci-shell:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- task: shfmt
name: "Run shfmt"
command: "shfmt -d ."
- task: shellcheck
name: "Run shellcheck"
command: "shellcheck **/*.sh"
name: Run ${{ matrix.task }}
steps:
- name: Checkout the repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup tools
uses: jdx/mise-action@13abe502c30c1559a5c37dff303831bab82c9402 # v2.2.3
- name: ${{ matrix.name }}
run: ${{ matrix.command }}

build:
runs-on: ubuntu-24.04
strategy:
Expand Down Expand Up @@ -64,7 +85,6 @@ jobs:
uses: jdx/mise-action@13abe502c30c1559a5c37dff303831bab82c9402 # v2.2.3
- name: Install dependencies
run: bun install --frozen-lockfile

- name: Fetch docs assets
if: ${{ matrix.kind == 'ja-JP' }}
run: bun run fetch-docs-ja-jp
Expand All @@ -73,45 +93,7 @@ jobs:
shell: bash
run: |
set -euxo pipefail

# Prepare docs.json
curl -L https://github.com/typst-community/dev-builds/releases/download/docs-${{ matrix.tag }}/docs.json \
-o public/docs.json
sd '/DOCS-BASE/' '${{ matrix.base }}' public/docs.json

# Prepare docs assets
curl -LO https://github.com/typst-community/dev-builds/releases/download/docs-${{ matrix.tag }}/docs-assets.zip
unzip docs-assets.zip
mv assets public/assets

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

# Configure metadata
TAG=${{ matrix.tag }}
# Strip the leading ‘v’ or convert to a valid format
${{ startsWith(matrix.tag, 'v') && 'VERSION=${TAG#v}' || 'VERSION="0.dev.${TAG}"' }}
cat << EOF > public/metadata.json
{
"\$schema": "../metadata.schema.json",
"language": "en-US",
"version": "$VERSION",
"typstOfficialUrl": "https://typst.app",
"typstOfficialDocsUrl": "https://typst.app/docs/",
"githubOrganizationUrl": "https://github.com/typst-community",
"socialLinks": [
{ "url": "https://github.com/typst-community/typst-docs-web" },
{
"title": "Discord (Typst)",
"url": "https://discord.gg/2uDybryKPe"
}
],
"originUrl": "https://example.com/",
"basePath": "${{ matrix.base }}",
"displayTranslationStatus": false
}
EOF
bash scripts/fetch-docs-assets.sh --tag "${{ matrix.tag }}" --base "${{ matrix.base }}" --dest public

- name: Run Vite build
run: bun run build
Expand Down
2 changes: 2 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ node = "22.11.0"
bun = "1.2.21"
pinact = "3.1.1"
sd = "1.0.0"
shfmt = "3.12.0"
shellcheck = "0.11.0"
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build]
command = "bash netlify-build.sh"
command = "bash scripts/netlify-build.sh"
publish = "_site"
152 changes: 152 additions & 0 deletions scripts/fetch-docs-assets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env bash
# Usage: fetch-docs-assets.sh [--tag TAG] [--base BASE] [--dest DEST]
# This script downloads docs.json and assets from the typst-community/dev-builds GitHub release
# and writes `public/docs.json`, `public/assets`, `public/favicon.png`, and `public/metadata.json`.

set -euo pipefail

print_usage() {
cat <<'EOF'
Usage: fetch-docs-assets.sh [--tag TAG] [--base BASE] [--dest DEST] [--origin ORIGIN]
Environment/args:
--tag TAG (required) Release tag to download, e.g. v0.14.0 or latest
--base BASE (required) Base path used by docs, e.g. / or /docs/
--dest DEST (optional) Destination directory to write files (default: public)
--origin ORIGIN (optional) Origin URL for the deployed site, without base path (default: https://example.com/)
This script performs the following:
- Downloads docs.json from the release tag
- Replaces '/DOCS-BASE/' placeholder in docs.json with the provided base
- Downloads docs-assets.zip and extracts it to destination/assets
- Downloads favicon and writes to destination/favicon.png
- Generates destination/metadata.json with basic deployment metadata
EOF
}

# Defaults
ORG="typst-community"
DEST="public"
ORIGIN="https://example.com/"
TAG=""
BASE=""

# Parse args
while [[ $# -gt 0 ]]; do
case "$1" in
--tag)
TAG="$2"
shift 2
;;
--base)
BASE="$2"
shift 2
;;
--dest)
DEST="$2"
shift 2
;;
--origin)
ORIGIN="$2"
shift 2
;;
--help | -h)
print_usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
print_usage
exit 2
;;
esac
done

if [[ -z "$TAG" || -z "$BASE" ]]; then
echo "--tag and --base are required" >&2
print_usage
exit 2
fi

mkdir -p "$DEST"

# Compute VERSION like the previous CI did
if [[ "$TAG" == v* ]]; then
VERSION="${TAG#v}"
else
VERSION="0.dev.${TAG}"
fi

RELEASE_BASE_URL="https://github.com/${ORG}/dev-builds/releases/download/docs-${TAG}"

# Download docs.json
DOCS_URL="${RELEASE_BASE_URL}/docs.json"
echo "Fetching docs from ${DOCS_URL}"
if ! curl -sSfL "$DOCS_URL" -o "${DEST}/docs.json"; then
echo "Failed to download docs.json from ${DOCS_URL}" >&2
exit 3
fi

# Replace placeholder '/DOCS-BASE/' with provided base in docs.json
# Use `sd` if available, else fallback to sed
if command -v sd >/dev/null 2>&1; then
sd '/DOCS-BASE/' "$BASE" "${DEST}/docs.json"
else
# Use portable sed: escape slashes
ESCAPED_BASE=$(printf '%s' "$BASE" | sed 's|/|\\/|g')
sed -i "s/\/DOCS-BASE\//${ESCAPED_BASE}/g" "${DEST}/docs.json"
fi

# Download assets and extract
ASSETS_URL="${RELEASE_BASE_URL}/docs-assets.zip"
ASSETS_ZIP="docs-assets.zip"
if curl -sSfL "$ASSETS_URL" -o "$ASSETS_ZIP"; then
echo "Extracting ${ASSETS_ZIP} to ${DEST}/assets"
# Clean up existing assets if present
rm -rf "${DEST}/assets"
unzip -q "$ASSETS_ZIP"
if [[ -d assets ]]; then
mv assets "${DEST}/assets"
else
echo "Downloaded zip did not contain assets/ folder" >&2
# keep build going; not necessarily fatal
fi
rm -f "$ASSETS_ZIP"
else
echo "No assets ZIP was found at ${ASSETS_URL} (continuing without error)" >&2
fi

# Download favicon
FAVICON_URL="https://github.com/${ORG}/org/raw/main/design/typst-community.icon.png"
if curl -sSfL "$FAVICON_URL" -o "${DEST}/favicon.png"; then
echo "Wrote favicon to ${DEST}/favicon.png"
else
echo "Failed to download favicon from ${FAVICON_URL} (continuing without error)" >&2
fi

# Write metadata.json
cat >"${DEST}/metadata.json" <<EOF
{
"\$schema": "../metadata.schema.json",
"language": "en-US",
"version": "${VERSION}",
"typstOfficialUrl": "https://typst.app",
"typstOfficialDocsUrl": "https://typst.app/docs/",
"githubOrganizationUrl": "https://github.com/${ORG}",
"socialLinks": [
{ "url": "https://github.com/${ORG}/typst-docs-web" },
{
"title": "Discord (Typst)",
"url": "https://discord.gg/2uDybryKPe"
}
],
"originUrl": "${ORIGIN}",
"basePath": "${BASE}",
"displayTranslationStatus": false
}
EOF

# Done
printf '\nFetch docs assets script done.\n'

exit 0
83 changes: 31 additions & 52 deletions netlify-build.sh → scripts/netlify-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ mkdir _site

# Prepare favicon
curl -L https://github.com/typst-community/org/raw/main/design/typst-community.icon.png \
-o _site/favicon.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
cat <<EOF >_site/index.html
<!DOCTYPE html>
<html lang="en">
<head>
Expand Down Expand Up @@ -54,6 +54,7 @@ cat << EOF > _site/index.html
<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.1/">en-US, v0.14.1</a></li>
<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>
Expand All @@ -71,67 +72,45 @@ EOF
# 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}
local VERSION="$1"
local BASE="en-US-${VERSION}"

bash scripts/fetch-docs-assets.sh \
--tag "${VERSION}" \
--base "/${BASE}/" \
--dest public \
--origin "${DEPLOY_URL}"
# $DEPLOY_URL will be set by netlify.
# 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.1
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
bash scripts/fetch-docs-assets.sh --tag "v0.13.1" --base "/irrelevant/"
rm public/{docs,metadata}.json

# 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

# Build
mise exec -- bun run build
Expand Down