-
Notifications
You must be signed in to change notification settings - Fork 1
chore: add docs assets download script #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+208
−93
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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`. | ||
3w36zj6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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" | ||
3w36zj6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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" | ||
3w36zj6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.