diff options
| author | Dave Tang <davetingpongtang@gmail.com> | 2026-06-23 16:31:48 +0900 |
|---|---|---|
| committer | Dave Tang <davetingpongtang@gmail.com> | 2026-06-23 16:31:48 +0900 |
| commit | c538086f5ad82d57c43726cb4536e36ad5c6320a (patch) | |
| tree | 52d4eb7592306bd7ff1d75eca98d2dc3336bec6e /scripts/setup.sh | |
| parent | 2b9d10dd8eb94e5c55d12698fb4b1acf7a7c6352 (diff) | |
Add LaTeX support
Diffstat (limited to 'scripts/setup.sh')
| -rwxr-xr-x | scripts/setup.sh | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/scripts/setup.sh b/scripts/setup.sh index d77d23e..bdebe9b 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -6,8 +6,8 @@ # bash setup-docsify.sh # # Downloads Docsify core, the search plugin, the Vue theme, the copy-to-clipboard -# plugin, and extra Prism languages (bash, yaml, python, r) — all -# served locally, no external CDN dependencies at runtime. +# plugin, extra Prism languages (bash, yaml, python, r), and KaTeX math rendering — +# 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 @@ -18,6 +18,8 @@ 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" +# KaTeX stylesheet/font version — must match the renderer bundled in docsify-katex@1.4.4 +KATEX_VERSION="0.11.1" # ── Argument check ────────────────────────────────────────────────────────────── if [[ $# -gt 0 ]]; then @@ -59,7 +61,7 @@ echo -e " Working in: $(pwd)" # ── Step 1: Directories ───────────────────────────────────────────────────────── step "Step 1 — Creating directory structure" -mkdir -p assets/js assets/css +mkdir -p assets/js assets/css assets/css/fonts ok "assets/js/" ok "assets/css/" @@ -91,6 +93,17 @@ fetch "${CDN}/prismjs@1/components/prism-yaml.min.js" assets/js/prism-yaml.mi 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 +# Math: docsify-katex@1.4.4 bundles the KaTeX renderer (2.x is broken). KaTeX's +# stylesheet loads its fonts from ./fonts/ beside it, so the woff2 files go in +# assets/css/fonts/. Stylesheet + fonts are pinned to the bundled KaTeX (KATEX_VERSION). +fetch "${CDN}/docsify-katex@1.4.4/dist/docsify-katex.js" assets/js/docsify-katex.js +fetch "${CDN}/katex@${KATEX_VERSION}/dist/katex.min.css" assets/css/katex.min.css +for f in $(grep -oE 'fonts/KaTeX_[^)]+\.woff2' assets/css/katex.min.css | sort -u); do + curl -sL --fail "${CDN}/katex@${KATEX_VERSION}/dist/$f" -o "assets/css/$f" \ + || die "Failed to download: $f" +done +ok "assets/css/fonts/ ($(ls -1 assets/css/fonts | wc -l) KaTeX woff2 files)" + # ── Step 3: index.html ────────────────────────────────────────────────────────── step "Step 3 — Creating index.html" @@ -105,6 +118,7 @@ cat > index.html << 'HTML' <meta name="viewport" content="width=device-width, initial-scale=1"> <title>My Docs</title> <link rel="stylesheet" href="assets/css/vue.css"> + <link rel="stylesheet" href="assets/css/katex.min.css"> </head> <body> <div id="app"></div> @@ -119,6 +133,7 @@ cat > index.html << 'HTML' <script src="assets/js/docsify.min.js"></script> <script src="assets/js/search.min.js"></script> <script src="assets/js/docsify-copy-code.min.js"></script> + <script src="assets/js/docsify-katex.js"></script> <!-- Extra Prism languages — Docsify bundles Prism core + html/css/js. Load after docsify. --> <script src="assets/js/prism-bash.min.js"></script> @@ -189,7 +204,8 @@ ok "Files: 644 | Directories: 755" # ── Verify ─────────────────────────────────────────────────────────────────────── step "Verifying file layout" -find . -not -path '*/\.*' | sort +find . -not -path '*/\.*' -not -path './assets/css/fonts*' | sort +echo "./assets/css/fonts/ ($(ls -1 assets/css/fonts 2>/dev/null | wc -l) KaTeX woff2 files)" # ── Done ───────────────────────────────────────────────────────────────────────── echo "" @@ -200,3 +216,4 @@ echo -e "Syntax highlighting: html, css, and javascript are built into Docsify;" echo -e "this setup adds bash, yaml, python, and r. To add more languages, download" echo -e "additional prism-<lang>.min.js files into assets/js/ and add their <script>" echo -e "tags to index.html. Copy-to-clipboard buttons are enabled on all code blocks." +echo -e "LaTeX math renders via KaTeX (inline \$...\$ and block \$\$...\$\$)." |
