-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-local.sh
More file actions
44 lines (40 loc) · 1.92 KB
/
Copy pathbuild-local.sh
File metadata and controls
44 lines (40 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
# Combined LOCAL preview: builds the home (main index) at / plus the named product
# trees under /<product>/, merged into ./public-local — mirroring production, where
# each product is its own Hugo build served under a path prefix.
#
# Why a script (not a single `hugo server`): home and product content both author
# root-relative URLs (e.g. /net/...), so they can only coexist when each is built
# with its own baseURL prefix and merged.
#
# Usage:
# ./build-local.sh # home + annotation (default)
# ./build-local.sh viewer signature # home + the listed products
# Then serve:
# python -m http.server 1313 --directory public-local --bind 127.0.0.1
set -euo pipefail
PORT="${PORT:-1313}"
OUT="public-local"
PRODUCTS=("$@")
[ ${#PRODUCTS[@]} -eq 0 ] && PRODUCTS=("annotation")
# Build home FIRST with --cleanDestinationDir (wipes stale output inside $OUT, including
# old product subdirs) — but not the $OUT dir itself, so a running http.server holding it
# open on Windows doesn't block the rebuild.
echo ">> home (main index) -> /"
hugo --config config-local.toml -b "http://localhost:$PORT/" -d "$PWD/$OUT" --cleanDestinationDir --minify
for p in "${PRODUCTS[@]}"; do
echo ">> $p -> /$p/"
hugo --configDir "config/sites/groupdocs/$p" --environment staging \
-b "http://localhost:$PORT/$p/" -d "$PWD/$OUT/$p" --cleanDestinationDir --minify
python resolve_md_links.py "$OUT/$p" --base-url "http://localhost:$PORT/$p" >/dev/null
bash move_md_to_ugly_urls.sh "$OUT/$p" >/dev/null
# Family page .md is served at /<product>.md (bucket root), not /<product>/index.md —
# mirror that locally (production does this via deploy_product.yml).
if [ -f "$OUT/$p/index.md" ]; then
cp "$OUT/$p/index.md" "$OUT/$p.md"
rm -f "$OUT/$p/index.md"
fi
done
echo
echo "Built ${#PRODUCTS[@]} product(s) + home into ./$OUT"
echo "Serve with: python -m http.server $PORT --directory $OUT --bind 127.0.0.1"