@@ -28,6 +28,31 @@ set -euo pipefail
2828cd " $( dirname " $0 " ) "
2929
3030PUBLISH_DIR=" ${1:? usage: publish-docs.sh <tika-site-publish-dir>} "
31+
32+ # Guard the 'rm -rf' below: the publish dir must already exist (it's a
33+ # tika-site checkout, not something we create) and not be a dangerously
34+ # short/root path that a typo could expand to.
35+ if [[ ! -d " ${PUBLISH_DIR} " ]]; then
36+ echo " PUBLISH_DIR '${PUBLISH_DIR} ' is not an existing directory." >&2
37+ echo " Point it at a tika-site 'publish/' checkout." >&2
38+ exit 1
39+ fi
40+ PUBLISH_DIR=" $( cd " ${PUBLISH_DIR} " && pwd -P) "
41+ if [[ " ${# PUBLISH_DIR} " -lt 4 || " ${PUBLISH_DIR} " != * " /" * ]]; then
42+ echo " Refusing to operate on suspiciously short PUBLISH_DIR '${PUBLISH_DIR} '." >&2
43+ exit 1
44+ fi
45+ # Confirm this looks like a tika-site 'publish/' dir: the documented argument
46+ # is always <tika-site-checkout>/publish, and the downstream 'svn add' step
47+ # hardcodes that name for the things written here (publish/docs, publish/_,
48+ # publish/search-index.js). Refusing a non-'publish' basename catches a
49+ # wrong-but-valid checkout before we 'rm -rf' inside it.
50+ if [[ " $( basename " ${PUBLISH_DIR} " ) " != " publish" ]]; then
51+ echo " PUBLISH_DIR '${PUBLISH_DIR} ' does not look like a tika-site publish dir" >&2
52+ echo " (expected its name to be 'publish'). Refusing to modify it." >&2
53+ exit 1
54+ fi
55+
3156DOCS_DIR=" ${PUBLISH_DIR} /docs"
3257
3358if [[ ! -d target/site ]]; then
@@ -40,12 +65,24 @@ mkdir -p "${DOCS_DIR}"
4065
4166# Strip the 'tika/' component dir prefix so URLs are /docs/X.Y.Z/...
4267cp -r target/site/tika/* " ${DOCS_DIR} /"
43- # UI assets one level above docs/, since HTML uses ../../_/ relative paths
44- cp -r target/site/_/ " ${PUBLISH_DIR} /_/"
68+ # UI assets one level above docs/, since HTML uses ../../_/ relative paths.
69+ # Replace wholesale: cp -r into an existing directory nests source as a
70+ # subdirectory (publish/_/_/), so remove first to keep the layout flat.
71+ # Refuse if '_' is a symlink: 'rm -rf _/' would follow it and wipe the
72+ # target's contents, and the cp below needs a real directory here anyway.
73+ if [[ -L " ${PUBLISH_DIR} /_" ]]; then
74+ echo " Refusing to remove '${PUBLISH_DIR} /_': it is a symlink, not a directory." >&2
75+ exit 1
76+ fi
77+ rm -rf " ${PUBLISH_DIR} /_"
78+ cp -r target/site/_ " ${PUBLISH_DIR} /_"
4579# Fix the root redirect and sitemap to match the flattened layout
4680sed ' s|tika/||g' target/site/index.html > " ${DOCS_DIR} /index.html"
4781sed ' s|/docs/tika/|/docs/|g' target/site/sitemap.xml > " ${DOCS_DIR} /sitemap.xml"
4882cp target/site/404.html " ${DOCS_DIR} /"
49- cp target/site/search-index.js " ${DOCS_DIR} /"
83+ # Lunr index lives next to _/ (one level above docs/), since HTML uses ../../search-index.js.
84+ # Remove the stale copy from its old publish/docs/ location left by earlier runs.
85+ rm -f " ${DOCS_DIR} /search-index.js"
86+ cp target/site/search-index.js " ${PUBLISH_DIR} /"
5087
5188echo " Published to: ${DOCS_DIR} /"
0 commit comments