Fix broken PDF hyperlinks

This commit is contained in:
Levi Neuwirth 2026-04-22 12:10:31 -04:00
parent 40ba09209c
commit 3a95a05284
6 changed files with 77 additions and 1 deletions

4
.gitignore vendored
View File

@ -65,6 +65,10 @@ levineuwirth_handover.zip
# Download with: make download-model # Download with: make download-model
static/models/ static/models/
# Vendored PDF.js viewer (~18 MB uncompressed, pinned in tools/download-pdfjs.sh).
# Download with: make download-pdfjs
static/pdfjs/
# Generated WebP companions (produced by tools/convert-images.sh at build time). # Generated WebP companions (produced by tools/convert-images.sh at build time).
# To intentionally commit a WebP, use: git add -f path/to/file.webp # To intentionally commit a WebP, use: git add -f path/to/file.webp
static/**/*.webp static/**/*.webp

View File

@ -1,4 +1,4 @@
.PHONY: build deploy sign download-model convert-images pdf-thumbs pdfs watch clean dev .PHONY: build deploy sign download-model download-pdfjs convert-images pdf-thumbs pdfs watch clean dev
# Source .env for GITHUB_TOKEN and GITHUB_REPO if it exists. # Source .env for GITHUB_TOKEN and GITHUB_REPO if it exists.
# .env format: KEY=value (one per line, no `export` prefix, no quotes needed). # .env format: KEY=value (one per line, no `export` prefix, no quotes needed).
@ -17,6 +17,7 @@ build:
@date +%s > data/build-start.txt @date +%s > data/build-start.txt
@./tools/convert-images.sh @./tools/convert-images.sh
@$(MAKE) -s pdf-thumbs @$(MAKE) -s pdf-thumbs
@./tools/download-pdfjs.sh
cabal run site -- build cabal run site -- build
pagefind --site _site pagefind --site _site
@if [ -d .venv ]; then \ @if [ -d .venv ]; then \
@ -37,6 +38,12 @@ sign:
download-model: download-model:
@./tools/download-model.sh @./tools/download-model.sh
# Vendor Mozilla's prebuilt PDF.js viewer into static/pdfjs/.
# Runs automatically as part of `build` (skips when already present).
# Files are gitignored; sha256-verified against tools/pdfjs-checksums.sha256.
download-pdfjs:
@./tools/download-pdfjs.sh
# Convert JPEG/PNG images to WebP companions (also runs automatically in build). # Convert JPEG/PNG images to WebP companions (also runs automatically in build).
# Requires cwebp: pacman -S libwebp / apt install webp # Requires cwebp: pacman -S libwebp / apt install webp
convert-images: convert-images:

Binary file not shown.

Binary file not shown.

64
tools/download-pdfjs.sh Executable file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env bash
# download-pdfjs.sh — Vendor Mozilla's prebuilt PDF.js viewer into static/pdfjs/.
#
# The Haskell link filter (build/Filters/Links.hs) rewrites every root-relative
# .pdf link to open through /pdfjs/web/viewer.html, so this viewer must be
# present in static/ for the site build to produce working PDF links.
#
# Run once before deploying. The extracted viewer is gitignored (~18 MB
# uncompressed); re-running is safe — the script skips when the viewer
# already exists.
#
# To bump the pinned version, set PDFJS_VERSION, re-run, then update
# tools/pdfjs-checksums.sha256 with the new archive SHA-256.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
PDFJS_DIR="$REPO_ROOT/static/pdfjs"
CHECKSUMS="$REPO_ROOT/tools/pdfjs-checksums.sha256"
PDFJS_VERSION="${PDFJS_VERSION:-5.6.205}"
ARCHIVE="pdfjs-${PDFJS_VERSION}-dist.zip"
URL="https://github.com/mozilla/pdf.js/releases/download/v${PDFJS_VERSION}/${ARCHIVE}"
if [ -f "$PDFJS_DIR/web/viewer.html" ]; then
echo "pdfjs: already present at $PDFJS_DIR/web/viewer.html (skipping)"
exit 0
fi
command -v unzip >/dev/null 2>&1 || {
echo "download-pdfjs: unzip not found — install it (pacman -S unzip / apt install unzip)" >&2
exit 1
}
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
echo "pdfjs: downloading $ARCHIVE"
curl -fsSL --progress-bar "$URL" -o "$tmpdir/$ARCHIVE"
if [ -f "$CHECKSUMS" ]; then
want=$(awk -v p="$ARCHIVE" '$2 == p { print $1; exit }' "$CHECKSUMS")
if [ -n "$want" ]; then
got=$(sha256sum "$tmpdir/$ARCHIVE" | awk '{ print $1 }')
if [ "$got" != "$want" ]; then
echo "pdfjs: sha256 mismatch for $ARCHIVE" >&2
echo " expected $want" >&2
echo " got $got" >&2
exit 1
fi
echo "pdfjs: sha256 verified"
else
echo "pdfjs: no pinned checksum for $ARCHIVE in $CHECKSUMS — skipping verification" >&2
fi
else
echo "pdfjs: $CHECKSUMS not found — skipping sha256 verification" >&2
fi
mkdir -p "$PDFJS_DIR"
echo "pdfjs: extracting to $PDFJS_DIR"
unzip -q -o "$tmpdir/$ARCHIVE" -d "$PDFJS_DIR"
echo "pdfjs: done. static/pdfjs/web/viewer.html is ready."
echo " Run 'make build' to include it in _site/."

View File

@ -0,0 +1 @@
0555ef47464e456125dcd0b9742cfa2aaed6d282e804e4dd1f1b99316b46ac00 pdfjs-5.6.205-dist.zip