File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ resolve_browser () {
5+ local candidate
6+ local env_candidates=(
7+ " ${PUPPETEER_EXECUTABLE_PATH:- } "
8+ " ${PDF_CHROME_BIN:- } "
9+ " ${CHROME_BIN:- } "
10+ " ${CHROMIUM_BIN:- } "
11+ " ${GOOGLE_CHROME_BIN:- } "
12+ )
13+
14+ for candidate in " ${env_candidates[@]} " ; do
15+ if [[ -n " $candidate " && -x " $candidate " ]]; then
16+ printf ' %s' " $candidate "
17+ return 0
18+ fi
19+ done
20+
21+ local names=(google-chrome google-chrome-stable chromium chromium-browser chrome)
22+ for candidate in " ${names[@]} " ; do
23+ if command -v " $candidate " > /dev/null 2>&1 ; then
24+ command -v " $candidate "
25+ return 0
26+ fi
27+ done
28+
29+ local local_cache=" ${PUPPETEER_CACHE_DIR:- $HOME / .cache/ puppeteer} "
30+ if [[ -d " $local_cache " ]]; then
31+ candidate=" $( find " $local_cache " -type f -name chrome -perm -111 2> /dev/null | head -n 1 || true) "
32+ if [[ -n " $candidate " ]]; then
33+ printf ' %s' " $candidate "
34+ return 0
35+ fi
36+ fi
37+
38+ local local_chromium=" $PWD /node_modules/puppeteer/.local-chromium"
39+ if [[ -d " $local_chromium " ]]; then
40+ candidate=" $( find " $local_chromium " -type f -name chrome -perm -111 2> /dev/null | head -n 1 || true) "
41+ if [[ -n " $candidate " ]]; then
42+ printf ' %s' " $candidate "
43+ return 0
44+ fi
45+ fi
46+
47+ return 1
48+ }
49+
50+ if [[ " ${1:- } " == " --probe" ]]; then
51+ resolve_browser > /dev/null
52+ exit $?
53+ fi
54+
55+ browser=" $( resolve_browser || true) "
56+ if [[ -z " $browser " ]]; then
57+ echo " No Chrome/Chromium executable found for PDF generation." >&2
58+ exit 1
59+ fi
60+
61+ exec " $browser " --no-sandbox --disable-setuid-sandbox " $@ "
Original file line number Diff line number Diff line change @@ -110,7 +110,19 @@ generate_pdf() {
110110 pdf_cmd=" npx starlight-to-pdf"
111111 fi
112112
113- $pdf_cmd " $url " --contents-links internal --filename aerynos --path " $DIST_DIR "
113+ local pdf_args=(" $url " --contents-links internal --filename aerynos --path " $DIST_DIR " )
114+ local browser_exec=" ${PDF_BROWSER_EXECUTABLE:- } "
115+ if [[ -z " $browser_exec " && (" ${CI:- } " == " true" || " ${GITHUB_ACTIONS:- } " == " true" ) ]]; then
116+ local wrapper=" $ROOT_DIR /scripts/chromium-no-sandbox.sh"
117+ if [[ -x " $wrapper " ]] && " $wrapper " --probe; then
118+ browser_exec=" $wrapper "
119+ fi
120+ fi
121+ if [[ -n " $browser_exec " ]]; then
122+ pdf_args+=(--browser-executable " $browser_exec " )
123+ fi
124+
125+ $pdf_cmd " ${pdf_args[@]} "
114126}
115127
116128copy_markdown
You can’t perform that action at this time.
0 commit comments