-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·127 lines (106 loc) · 4.24 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·127 lines (106 loc) · 4.24 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# @file
# Builds a Hugo site hosted on a Cloudflare Worker.
#
# The Cloudflare Worker automatically installs Node.js dependencies.
#------------------------------------------------------------------------------
# Exit on error, undefined variables, or pipe failures
set -euo pipefail
build_temp_dir=""
# Perform cleanup
cleanup() {
if [[ -n "${build_temp_dir:-}" && -d "${build_temp_dir}" ]]; then
rm -rf "${build_temp_dir}"
fi
}
# Register the cleanup trap
trap cleanup EXIT SIGINT SIGTERM
main() {
# Define tool versions
DART_SASS_VERSION=1.99.0
GO_VERSION=1.26.1
HUGO_VERSION=0.160.1
NODE_VERSION=24.14.1
OS_NAME="$(uname -s)"
OS_ARCH="$(uname -m)"
# Set the build timezone
export TZ=Europe/Oslo
if [[ "${OS_NAME}" == "Linux" && "${OS_ARCH}" == "x86_64" ]]; then
# Create and move into a temporary directory for downloads
build_temp_dir=$(mktemp -d)
pushd "${build_temp_dir}" > /dev/null
# Create the local tools directory
mkdir -p "${HOME}/.local"
# Install Dart Sass
echo "Installing Dart Sass ${DART_SASS_VERSION}..."
curl -sLJO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
export PATH="${HOME}/.local/dart-sass:${PATH}"
# Install Go
echo "Installing Go ${GO_VERSION}..."
curl -sLJO "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz"
tar -C "${HOME}/.local" -xf "go${GO_VERSION}.linux-amd64.tar.gz"
export PATH="${HOME}/.local/go/bin:${PATH}"
# Install Hugo
echo "Installing Hugo ${HUGO_VERSION}..."
curl -sLJO "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_linux-amd64.tar.gz"
mkdir -p "${HOME}/.local/hugo"
tar -C "${HOME}/.local/hugo" -xf "hugo_${HUGO_VERSION}_linux-amd64.tar.gz"
export PATH="${HOME}/.local/hugo:${PATH}"
# Install Node.js
echo "Installing Node.js ${NODE_VERSION}..."
curl -sLJO "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz"
tar -C "${HOME}/.local" -xf "node-v${NODE_VERSION}-linux-x64.tar.xz"
export PATH="${HOME}/.local/node-v${NODE_VERSION}-linux-x64/bin:${PATH}"
# Return to the project root
popd > /dev/null
else
echo "Using local build tools on ${OS_NAME}/${OS_ARCH}; pinned downloads run on Linux x86_64 CI."
fi
# Verify installations
echo "Verifying installations..."
if command -v sass > /dev/null; then
echo Dart Sass: "$(sass --version)"
elif [[ "${OS_NAME}" == "Linux" && "${OS_ARCH}" == "x86_64" ]]; then
echo "Dart Sass: missing"
exit 1
else
echo "Dart Sass: not installed locally"
fi
if command -v go > /dev/null; then
echo Go: "$(go version)"
elif [[ "${OS_NAME}" == "Linux" && "${OS_ARCH}" == "x86_64" ]]; then
echo "Go: missing"
exit 1
else
echo "Go: not installed locally"
fi
echo Hugo: "$(hugo version)"
echo Node.js: "$(node --version)"
# Configure Git
echo "Configuring Git..."
git config core.quotepath false
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
git fetch --unshallow
fi
# Build the main site.
echo "Building the main site..."
hugo build --config hugo.yml --gc --minify
# Top-level /404.html fallback for URLs that don't carry a language prefix.
# Cloudflare's `not_found_handling = "404-page"` walks up the directory tree
# looking for the nearest 404.html; /en/404.html handles /en/* misses, and
# this copy handles misses at the root (e.g. /typo).
echo "Copying default-language 404 to site root..."
cp public/en/404.html public/404.html
# Build the dedicated brand standards site into a host-specific subtree.
# The Worker rewrites brand.vanityurls.link HTML requests to /brand/* while
# shared static assets remain available from the root asset bucket.
echo "Building the brand site..."
hugo build --config hugo.brand.yml --destination public/brand --gc --minify
# Build the search index
# Pagefind is a devDependency; the Cloudflare Worker runs `npm ci` automatically.
echo "Building the search index..."
npx pagefind --site public
}
main "$@"