-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpreview.sh
More file actions
executable file
·118 lines (98 loc) · 3.13 KB
/
preview.sh
File metadata and controls
executable file
·118 lines (98 loc) · 3.13 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
#!/usr/bin/env bash
#
# Preview the documentation locally using Hugo.
#
# Usage:
# ./docs/preview.sh # start a local Hugo server on port 1313
# ./docs/preview.sh build # generate static HTML in .docs-preview/public
#
# Requirements:
# - hugo (https://gohugo.io/installation/)
# - git (to fetch the hugo-book theme)
# - go (for Hugo module mounts)
#
set -euo pipefail
DOCS_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_DIR="$(cd "${DOCS_DIR}/.." && pwd)"
SITE_DIR="${REPO_DIR}/.docs-preview"
THEME_REPO="https://github.com/alex-shpak/hugo-book.git"
# To update the theme, change THEME_REF to the desired commit SHA from
# https://github.com/alex-shpak/hugo-book/commits/main
# The script detects mismatches and re-fetches automatically.
# This commit matches the version used by the streamshub-site.
THEME_REF="9d6ad30e9e44077846ece81cdd9e59122fccf4af"
THEME_DIR="${SITE_DIR}/themes/hugo-book"
## Check prerequisites ##
for cmd in hugo git go; do
if ! command -v "${cmd}" &>/dev/null; then
echo "Error: Required command '${cmd}' is not installed."
exit 1
fi
done
## Set up site structure ##
mkdir -p "${SITE_DIR}"
## Initialise Go module (required for Hugo mounts) ##
if [ ! -f "${SITE_DIR}/go.mod" ]; then
(cd "${SITE_DIR}" && go mod init docs-preview)
fi
## Fetch theme (cached across runs) ##
fetch_theme() {
echo "Fetching hugo-book theme at ${THEME_REF}..."
rm -rf "${THEME_DIR}"
mkdir -p "${THEME_DIR}"
git -C "${THEME_DIR}" init -q
git -C "${THEME_DIR}" remote add origin "${THEME_REPO}"
git -C "${THEME_DIR}" fetch --depth 1 origin "${THEME_REF}"
git -C "${THEME_DIR}" checkout -q FETCH_HEAD
}
if [ ! -d "${THEME_DIR}/.git" ]; then
fetch_theme
elif ! git -C "${THEME_DIR}" cat-file -e "${THEME_REF}^{commit}" 2>/dev/null; then
echo "Cached theme is at a different version; updating..."
fetch_theme
else
echo "Using cached hugo-book theme (${THEME_REF:0:12})."
fi
## Generate hugo.toml ##
# Mirrors the relevant settings from the streamshub-site hugo.toml.
# Uses Hugo module mounts to reference the docs directory directly.
cat > "${SITE_DIR}/hugo.toml" << CONFIG
baseURL = 'http://localhost:1313/'
languageCode = 'en-us'
title = 'StreamsHub Developer Quick-Start — Local Preview'
theme = 'hugo-book'
disablePathToLower = true
[markup]
[markup.tableOfContents]
startLevel = 1
[markup.highlight]
style = "catppuccin-macchiato"
[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true
[params]
BookTheme = 'dark'
BookSection = '/'
BookPortableLinks = true
# Mount the docs directory as content/docs so Hugo reads it directly.
[[module.mounts]]
source = '${DOCS_DIR}'
target = 'content/docs'
CONFIG
## Run Hugo ##
cd "${SITE_DIR}"
case "${1:-serve}" in
build)
echo "Building static site..."
hugo --gc --minify
echo "Output: ${SITE_DIR}/public/"
;;
serve|*)
echo ""
echo "Starting local preview server..."
echo "Open http://localhost:1313/docs/ in your browser."
echo "Press Ctrl+C to stop."
echo ""
hugo server --buildDrafts --disableFastRender
;;
esac