Skip to content

Commit f0d83cc

Browse files
ci: unify netlify build script with docs asssets download script, and add en-US v0.14.1
1 parent 7f7a866 commit f0d83cc

File tree

3 files changed

+29
-44
lines changed

3 files changed

+29
-44
lines changed

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[build]
2-
command = "bash netlify-build.sh"
2+
command = "bash scripts/netlify-build.sh"
33
publish = "_site"

scripts/fetch-docs-assets.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ set -euo pipefail
77

88
print_usage() {
99
cat <<'EOF'
10-
Usage: fetch-docs-assets.sh [--tag TAG] [--base BASE] [--dest DEST]
10+
Usage: fetch-docs-assets.sh [--tag TAG] [--base BASE] [--dest DEST] [--origin ORIGIN]
1111
1212
Environment/args:
13-
--tag TAG (required) Release tag to download, e.g. v0.14.0 or latest
14-
--base BASE (required) Base path used by docs, e.g. / or /docs/
15-
--dest DEST (optional) Destination directory to write files (default: public)
13+
--tag TAG (required) Release tag to download, e.g. v0.14.0 or latest
14+
--base BASE (required) Base path used by docs, e.g. / or /docs/
15+
--dest DEST (optional) Destination directory to write files (default: public)
16+
--origin ORIGIN (optional) Origin URL for the deployed site, without base path (default: https://example.com/)
1617
1718
This script performs the following:
1819
- Downloads docs.json from the release tag
@@ -26,6 +27,7 @@ EOF
2627
# Defaults
2728
ORG="typst-community"
2829
DEST="public"
30+
ORIGIN="https://example.com/"
2931
TAG=""
3032
BASE=""
3133

@@ -44,6 +46,10 @@ while [[ $# -gt 0 ]]; do
4446
DEST="$2"
4547
shift 2
4648
;;
49+
--origin)
50+
ORIGIN="$2"
51+
shift 2
52+
;;
4753
--help | -h)
4854
print_usage
4955
exit 0
@@ -134,7 +140,7 @@ cat >"${DEST}/metadata.json" <<EOF
134140
"url": "https://discord.gg/2uDybryKPe"
135141
}
136142
],
137-
"originUrl": "https://example.com/",
143+
"originUrl": "${ORIGIN}",
138144
"basePath": "${BASE}",
139145
"displayTranslationStatus": false
140146
}

netlify-build.sh renamed to scripts/netlify-build.sh

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ cat <<EOF >_site/index.html
5454
<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>
5555
<p>This website is for developing typst-docs-web. Its contents might be changed at anytime.</p>
5656
<ul>
57+
<li><a href="./en-US-v0.14.1/">en-US, v0.14.1</a></li>
5758
<li><a href="./en-US-v0.14.0/">en-US, v0.14.0</a></li>
5859
<li><a href="./en-US-v0.13.1/">en-US, v0.13.1</a></li>
5960
<li><a href="./ja-JP/">ja-JP, v0.13.1</a></li>
@@ -72,36 +73,14 @@ EOF
7273

7374
build_en_US() {
7475
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.
76+
local BASE="en-US-${VERSION}"
77+
78+
bash scripts/fetch-docs-assets.sh \
79+
--tag "${VERSION}" \
80+
--base "/${BASE}/" \
81+
--dest public \
82+
--origin "${DEPLOY_URL}"
83+
# $DEPLOY_URL will be set by netlify.
10584
# https://docs.netlify.com/build/configure-builds/environment-variables/#deploy-urls-and-metadata
10685

10786
# Build
@@ -112,11 +91,19 @@ EOF
11291
rm -r public/{docs.json,assets,metadata.json}
11392
}
11493

94+
build_en_US v0.14.1
11595
build_en_US v0.14.0
11696
build_en_US v0.13.1
11797

11898
# 3.2. Build ja-JP
11999

100+
# Prepare docs assets
101+
# At present, typst-jp do not translate comments within example code.
102+
# And there is no simple way to download assets from GitHub Actions or the gh-pages branch.
103+
# Therefore, we reuse the assets from the official version.
104+
bash scripts/fetch-docs-assets.sh --tag "v0.13.1" --base "/irrelevant/"
105+
rm public/{docs,metadata}.json
106+
120107
# Prepare JSON files
121108
mise exec -- bun run fetch-docs-ja-jp
122109
sd '"/docs/' '"/ja-JP/' public/docs.json
@@ -125,14 +112,6 @@ sd --fixed-strings \
125112
'"basePath": "/ja-JP/",' \
126113
public/metadata.json
127114

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-
136115
# Build
137116
mise exec -- bun run build
138117
mv dist _site/ja-JP

0 commit comments

Comments
 (0)