@@ -7,20 +7,22 @@ set -euo pipefail
77
88print_usage () {
99 cat << 'EOF '
10- Usage: fetch-docs-assets.sh [--tag TAG] [--base BASE] [--dest DEST] [--origin ORIGIN ]
10+ Usage: fetch-docs-assets.sh [--tag TAG] [--base BASE] [options... ]
1111
1212Environment/args:
1313 --tag TAG (required) Release tag to download, e.g. v0.14.0 or latest
1414 --base BASE (required) Base path used by docs, e.g. / or /docs/
1515 --dest DEST (optional) Destination directory to write files (default: public)
1616 --origin ORIGIN (optional) Origin URL for the deployed site, without base path (default: https://example.com/)
17+ --skip FILE (optional) Skip one of the files (docs.json, docs-assets, favicon, metadata), can be specified multiple times
1718
1819This script performs the following:
19- - Downloads docs.json from the release tag
20- - Replaces '/DOCS-BASE/' placeholder in docs.json with the provided base
21- - Downloads docs-assets.zip and extracts it to destination/assets
22- - Downloads favicon and writes to destination/favicon.png
23- - Generates destination/metadata.json with basic deployment metadata
20+ - docs.json:
21+ - Downloads docs.json from the release tag
22+ - Replaces '/DOCS-BASE/' placeholder in docs.json with the provided base
23+ - docs-assets: Downloads docs-assets.zip and extracts it to destination/assets
24+ - favicon: Downloads favicon and writes to destination/favicon.png
25+ - metadata: Generates destination/metadata.json with basic deployment metadata
2426EOF
2527}
2628
@@ -30,6 +32,7 @@ DEST="public"
3032ORIGIN=" https://example.com/"
3133TAG=" "
3234BASE=" "
35+ SKIP=()
3336
3437# Parse args
3538while [[ $# -gt 0 ]]; do
@@ -50,6 +53,19 @@ while [[ $# -gt 0 ]]; do
5053 ORIGIN=" $2 "
5154 shift 2
5255 ;;
56+ --skip)
57+ case " $2 " in
58+ docs.json | docs-assets | favicon | metadata)
59+ SKIP+=(" $2 " )
60+ shift 2
61+ ;;
62+ * )
63+ echo " Invalid --skip option: $2 " >&2
64+ print_usage
65+ exit 2
66+ ;;
67+ esac
68+ ;;
5369 --help | -h)
5470 print_usage
5571 exit 0
8096RELEASE_BASE_URL=" https://github.com/${ORG} /dev-builds/releases/download/docs-${TAG} "
8197
8298# Download docs.json
83- DOCS_URL=" ${RELEASE_BASE_URL} /docs.json"
84- echo " Fetching docs from ${DOCS_URL} "
85- if ! curl -sSfL " $DOCS_URL " -o " ${DEST} /docs.json" ; then
86- echo " Failed to download docs.json from ${DOCS_URL} " >&2
87- exit 3
88- fi
89-
90- # Replace placeholder '/DOCS-BASE/' with provided base in docs.json
91- # Use `sd` if available, else fallback to sed
92- if command -v sd > /dev/null 2>&1 ; then
93- sd ' /DOCS-BASE/' " $BASE " " ${DEST} /docs.json"
99+ if printf ' %s\n' " ${SKIP[@]} " | grep -qx " docs.json" ; then
100+ echo " Skipping docs.json download as per --skip option"
94101else
95- # Use portable sed: escape slashes
96- ESCAPED_BASE=$( printf ' %s' " $BASE " | sed ' s|/|\\/|g' )
97- sed -i " s/\/DOCS-BASE\//${ESCAPED_BASE} /g" " ${DEST} /docs.json"
102+ DOCS_URL=" ${RELEASE_BASE_URL} /docs.json"
103+ echo " Fetching docs from ${DOCS_URL} "
104+ if ! curl -sSfL " $DOCS_URL " -o " ${DEST} /docs.json" ; then
105+ echo " Failed to download docs.json from ${DOCS_URL} " >&2
106+ exit 3
107+ fi
108+
109+ # Replace placeholder '/DOCS-BASE/' with provided base in docs.json
110+ # Use `sd` if available, else fallback to sed
111+ if command -v sd > /dev/null 2>&1 ; then
112+ sd ' /DOCS-BASE/' " $BASE " " ${DEST} /docs.json"
113+ else
114+ # Use portable sed: escape slashes
115+ ESCAPED_BASE=$( printf ' %s' " $BASE " | sed ' s|/|\\/|g' )
116+ sed -i " s/\/DOCS-BASE\//${ESCAPED_BASE} /g" " ${DEST} /docs.json"
117+ fi
98118fi
99119
100120# Download assets and extract
101- ASSETS_URL=" ${RELEASE_BASE_URL} /docs-assets.zip"
102- ASSETS_ZIP=" docs-assets.zip"
103- if curl -sSfL " $ASSETS_URL " -o " $ASSETS_ZIP " ; then
104- echo " Extracting ${ASSETS_ZIP} to ${DEST} /assets"
105- # Clean up existing assets if present
106- rm -rf " ${DEST} /assets"
107- unzip -q " $ASSETS_ZIP "
108- if [[ -d assets ]]; then
109- mv assets " ${DEST} /assets"
121+ if printf ' %s\n' " ${SKIP[@]} " | grep -qx " docs-assets" ; then
122+ echo " Skipping docs-assets download as per --skip option"
123+ else
124+ ASSETS_URL=" ${RELEASE_BASE_URL} /docs-assets.zip"
125+ ASSETS_ZIP=" docs-assets.zip"
126+ if curl -sSfL " $ASSETS_URL " -o " $ASSETS_ZIP " ; then
127+ echo " Extracting ${ASSETS_ZIP} to ${DEST} /assets"
128+ # Clean up existing assets if present
129+ rm -rf " ${DEST} /assets"
130+ unzip -q " $ASSETS_ZIP "
131+ if [[ -d assets ]]; then
132+ mv assets " ${DEST} /assets"
133+ else
134+ echo " Downloaded zip did not contain assets/ folder" >&2
135+ # keep build going; not necessarily fatal
136+ fi
137+ rm -f " $ASSETS_ZIP "
110138 else
111- echo " Downloaded zip did not contain assets/ folder" >&2
112- # keep build going; not necessarily fatal
139+ echo " No assets ZIP was found at ${ASSETS_URL} (continuing without error)" >&2
113140 fi
114- rm -f " $ASSETS_ZIP "
115- else
116- echo " No assets ZIP was found at ${ASSETS_URL} (continuing without error)" >&2
117141fi
118142
119143# Download favicon
120- FAVICON_URL=" https://github.com/${ORG} /org/raw/main/design/typst-community.icon.png"
121- if curl -sSfL " $FAVICON_URL " -o " ${DEST} /favicon.png" ; then
122- echo " Wrote favicon to ${DEST} /favicon.png"
144+ if printf ' %s\n' " ${SKIP[@]} " | grep -qx " favicon" ; then
145+ echo " Skipping favicon download as per --skip option"
123146else
124- echo " Failed to download favicon from ${FAVICON_URL} (continuing without error)" >&2
147+ FAVICON_URL=" https://github.com/${ORG} /org/raw/main/design/typst-community.icon.png"
148+ if curl -sSfL " $FAVICON_URL " -o " ${DEST} /favicon.png" ; then
149+ echo " Wrote favicon to ${DEST} /favicon.png"
150+ else
151+ echo " Failed to download favicon from ${FAVICON_URL} (continuing without error)" >&2
152+ fi
125153fi
126154
127155# Write metadata.json
128- cat > " ${DEST} /metadata.json" << EOF
156+ if printf ' %s\n' " ${SKIP[@]} " | grep -qx " metadata" ; then
157+ echo " Skipping metadata generation as per --skip option"
158+ else
159+ cat > " ${DEST} /metadata.json" << EOF
129160{
130161 "\$ schema": "../metadata.schema.json",
131162 "language": "en-US",
@@ -145,6 +176,7 @@ cat >"${DEST}/metadata.json" <<EOF
145176 "displayTranslationStatus": false
146177}
147178EOF
179+ fi
148180
149181# Done
150182printf ' \nFetch docs assets script done.\n'
0 commit comments