summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDave Tang <davetingpongtang@gmail.com>2026-06-23 15:47:47 +0900
committerDave Tang <davetingpongtang@gmail.com>2026-06-23 15:47:47 +0900
commit01fc8071fc4e12ef23a6ef2f78bfa77eecc626a2 (patch)
tree4aa7049084478cac7517edd09e54bdfb015fc29a /scripts
parent0c3d06d3f2a7caf6640d83db361f6de444d717dc (diff)
Add prism and code copy by default
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/setup.sh137
1 files changed, 64 insertions, 73 deletions
diff --git a/scripts/setup.sh b/scripts/setup.sh
index ab24775..a404eae 100755
--- a/scripts/setup.sh
+++ b/scripts/setup.sh
@@ -3,38 +3,40 @@
#
# Run this script from your Apache document root:
# cd /path/to/docroot
-# bash setup-docsify.sh [--with-prism] [--with-copy-code]
+# bash setup-docsify.sh
#
-# Options:
-# --with-prism Also download Prism and enable syntax highlighting in index.html
-# --with-copy-code Also download the docsify-copy-code plugin (copy button on code blocks)
+# Downloads Docsify core, the search plugin, the Vue theme, the copy-to-clipboard
+# plugin, and Prism syntax highlighting (bash, yaml, javascript, python, r) — all
+# served locally, no external CDN dependencies at runtime.
+#
+# Re-running in an existing site is safe: it refreshes the assets and regenerates
+# index.html, but never overwrites Markdown files (README.md, _sidebar.md, and any
+# pages you have added) that already exist.
set -euo pipefail
# ── Configuration ───────────────────────────────────────────────────────────────
# Use "4" for the latest 4.x release, or pin to a specific version e.g. "4.13.1"
DOCSIFY_VERSION="4"
-PRISM=false
-COPY_CODE=false
-# ── Argument parsing ────────────────────────────────────────────────────────────
-for arg in "$@"; do
- case "$arg" in
- --with-prism) PRISM=true ;;
- --with-copy-code) COPY_CODE=true ;;
- *) echo "Unknown option: $arg" >&2; exit 1 ;;
- esac
-done
+# ── Argument check ──────────────────────────────────────────────────────────────
+if [[ $# -gt 0 ]]; then
+ echo "This script takes no options (got: $*)." >&2
+ echo "Usage: bash setup-docsify.sh" >&2
+ exit 1
+fi
# ── Output helpers ──────────────────────────────────────────────────────────────
GREEN='\033[0;32m'
BLUE='\033[0;34m'
+YELLOW='\033[0;33m'
RED='\033[0;31m'
BOLD='\033[1m'
NC='\033[0m'
step() { echo -e "\n${BLUE}${BOLD}==> $1${NC}"; }
ok() { echo -e " ${GREEN}✓${NC} $1"; }
+skip() { echo -e " ${YELLOW}•${NC} $1"; }
die() { echo -e " ${RED}✗${NC} $1" >&2; exit 1; }
# ── Preflight checks ────────────────────────────────────────────────────────────
@@ -46,7 +48,8 @@ ok "curl $(curl --version | head -1 | awk '{print $2}')"
if [[ -f index.html ]]; then
echo -e " ${RED}!${NC} index.html already exists in: $(pwd)"
- echo -e " This script will overwrite index.html and all boilerplate .md files."
+ echo -e " This re-downloads assets and regenerates index.html (edits to"
+ echo -e " index.html will be lost). Existing Markdown files are left untouched."
read -r -p " Continue? [y/N] " reply
[[ "${reply,,}" == "y" ]] || { echo "Aborted."; exit 0; }
fi
@@ -71,33 +74,30 @@ fetch() {
ok "$dest"
}
-fetch "${CDN}/docsify@${DOCSIFY_VERSION}/lib/docsify.min.js" assets/js/docsify.min.js
-fetch "${CDN}/docsify@${DOCSIFY_VERSION}/lib/plugins/search.min.js" assets/js/search.min.js
+# Core Docsify, search plugin, and theme
+fetch "${CDN}/docsify@${DOCSIFY_VERSION}/lib/docsify.min.js" assets/js/docsify.min.js
+fetch "${CDN}/docsify@${DOCSIFY_VERSION}/lib/plugins/search.min.js" assets/js/search.min.js
fetch "${CDN}/docsify@${DOCSIFY_VERSION}/themes/vue.css" assets/css/vue.css
-if [[ "$PRISM" == true ]]; then
- echo ""
- echo " Downloading Prism syntax highlighting..."
- fetch "${CDN}/prismjs@1/components/prism-core.min.js" assets/js/prism-core.min.js
- fetch "${CDN}/prismjs@1/components/prism-bash.min.js" assets/js/prism-bash.min.js
- fetch "${CDN}/prismjs@1/components/prism-yaml.min.js" assets/js/prism-yaml.min.js
- fetch "${CDN}/prismjs@1/components/prism-javascript.min.js" assets/js/prism-javascript.min.js
-fi
+# Copy-to-clipboard plugin (injects its own CSS — no separate stylesheet needed)
+fetch "${CDN}/docsify-copy-code@3/dist/docsify-copy-code.min.js" assets/js/docsify-copy-code.min.js
-if [[ "$COPY_CODE" == true ]]; then
- echo ""
- echo " Downloading copy-to-clipboard plugin..."
- fetch "${CDN}/docsify-copy-code@3/dist/docsify-copy-code.min.js" assets/js/docsify-copy-code.min.js
-fi
+# Prism syntax highlighting: core engine, then clike (required by javascript),
+# then the individual languages.
+fetch "${CDN}/prismjs@1/components/prism-core.min.js" assets/js/prism-core.min.js
+fetch "${CDN}/prismjs@1/components/prism-clike.min.js" assets/js/prism-clike.min.js
+fetch "${CDN}/prismjs@1/components/prism-javascript.min.js" assets/js/prism-javascript.min.js
+fetch "${CDN}/prismjs@1/components/prism-bash.min.js" assets/js/prism-bash.min.js
+fetch "${CDN}/prismjs@1/components/prism-yaml.min.js" assets/js/prism-yaml.min.js
+fetch "${CDN}/prismjs@1/components/prism-python.min.js" assets/js/prism-python.min.js
+fetch "${CDN}/prismjs@1/components/prism-r.min.js" assets/js/prism-r.min.js
# ── Step 3: index.html ──────────────────────────────────────────────────────────
step "Step 3 — Creating index.html"
-# index.html is assembled in parts so the Prism <script> block can be
-# included or omitted cleanly. The heredoc delimiters are single-quoted
-# ('HTML_HEAD') to prevent the shell from expanding $docsify.
-{
- cat << 'HTML_HEAD'
+# The heredoc delimiter is single-quoted ('HTML') so the shell does not expand
+# $docsify inside the template.
+cat > index.html << 'HTML'
<!DOCTYPE html>
<html lang="en">
<head>
@@ -119,39 +119,40 @@ step "Step 3 — Creating index.html"
</script>
<script src="assets/js/docsify.min.js"></script>
<script src="assets/js/search.min.js"></script>
-HTML_HEAD
-
- if [[ "$COPY_CODE" == true ]]; then
- cat << 'HTML_COPYCODE'
-
- <!-- Copy-to-clipboard button for code blocks -->
<script src="assets/js/docsify-copy-code.min.js"></script>
-HTML_COPYCODE
- fi
-
- if [[ "$PRISM" == true ]]; then
- cat << 'HTML_PRISM'
- <!-- Prism syntax highlighting -->
+ <!-- Prism: core engine first, then clike (required by javascript), then languages -->
<script src="assets/js/prism-core.min.js"></script>
+ <script src="assets/js/prism-clike.min.js"></script>
+ <script src="assets/js/prism-javascript.min.js"></script>
<script src="assets/js/prism-bash.min.js"></script>
<script src="assets/js/prism-yaml.min.js"></script>
- <script src="assets/js/prism-javascript.min.js"></script>
-HTML_PRISM
- fi
-
- cat << 'HTML_FOOT'
+ <script src="assets/js/prism-python.min.js"></script>
+ <script src="assets/js/prism-r.min.js"></script>
</body>
</html>
-HTML_FOOT
-} > index.html
+HTML
ok "index.html"
# ── Step 4: Boilerplate content ─────────────────────────────────────────────────
-step "Step 4 — Creating boilerplate content"
+step "Step 4 — Boilerplate content (created only if missing)"
+
+# Write the heredoc on stdin to $1, but never clobber an existing file — so
+# re-running refreshes the assets and index.html without touching your content.
+write_boilerplate() {
+ local dest="$1"
+ local content
+ content="$(cat)"
+ if [[ -e "$dest" ]]; then
+ skip "$dest (exists — left unchanged)"
+ else
+ printf '%s\n' "$content" > "$dest"
+ ok "$dest"
+ fi
+}
-cat > README.md << 'EOF'
+write_boilerplate README.md << 'EOF'
# Welcome
This is the home page of your documentation site.
@@ -161,15 +162,13 @@ Edit `README.md` to replace this content.
- [Getting Started](getting-started.md)
EOF
-ok "README.md"
-cat > _sidebar.md << 'EOF'
+write_boilerplate _sidebar.md << 'EOF'
- [Home](/)
- [Getting Started](getting-started.md)
EOF
-ok "_sidebar.md"
-cat > getting-started.md << 'EOF'
+write_boilerplate getting-started.md << 'EOF'
# Getting Started
This is an example page. Replace this content with your own documentation.
@@ -183,7 +182,6 @@ Write your content here using standard Markdown.
Docsify will automatically generate sidebar anchors for H2 headings
when `subMaxLevel: 2` is set in `index.html`.
EOF
-ok "getting-started.md"
# ── Step 5: Permissions ─────────────────────────────────────────────────────────
step "Step 5 — Setting file permissions"
@@ -201,15 +199,8 @@ find . -not -path '*/\.*' | sort
echo ""
echo -e "${GREEN}${BOLD}Setup complete.${NC}"
echo -e "Open your site in a browser to verify."
-
-if [[ "$PRISM" == true ]]; then
- echo ""
- echo -e "Prism is enabled for: bash, yaml, javascript."
- echo -e "To add more languages, download additional prism-*.min.js files"
- echo -e "into assets/js/ and add their <script> tags to index.html."
-fi
-
-if [[ "$COPY_CODE" == true ]]; then
- echo ""
- echo -e "Copy-to-clipboard buttons are enabled on all code blocks."
-fi
+echo ""
+echo -e "Syntax highlighting (Prism) is enabled for: bash, yaml, javascript, python, r."
+echo -e "To add more languages, download additional prism-*.min.js files into"
+echo -e "assets/js/ and add their <script> tags to index.html (after prism-core.min.js)."
+echo -e "Copy-to-clipboard buttons are enabled on all code blocks."