Skip to content

feat: self-host KaTeX so math pages load no third-party CDN (#118)#125

Merged
sc2ben merged 4 commits into
mainfrom
118-selfhost-katex
Jul 8, 2026
Merged

feat: self-host KaTeX so math pages load no third-party CDN (#118)#125
sc2ben merged 4 commits into
mainfrom
118-selfhost-katex

Conversation

@tsunaminoai

Copy link
Copy Markdown
Contributor

Follow-up to PR #124 (web UX). Completes the "no third-party CDN" hardening for math-enabled pages.

What

templates/macros/math.html loaded KaTeX 0.11.1 — CSS, JS, auto-render, and ~20 font families — from cdn.jsdelivr.net on any page that opts into math (math = true). That's the same offline/privacy leak the #118 icons item flagged, just on a different subset of pages.

This vendors KaTeX 0.11.1 under static/katex/ (CSS, JS, auto-render, and all font formats: woff2/woff/ttf) and points the macro at the local copy, dropping the CDN URLs and their SRI/crossorigin attributes. Math-enabled pages now render fully offline.

It also excludes the vendored asset dirs (static/katex, static/fontawesome) from treefmt / pre-commit formatting so their upstream minified form is preserved — prettier was otherwise de-minifying katex.min.js (255 KB → 446 KB).

Verified

  • zola build clean; the example policy's $$Risk = Threat \times Vulnerability \times Impact$$ renders correctly typeset from the local copy (checked via zola serve + headless screenshot).
  • The built math page references only /katex/... — zero jsdelivr requests for KaTeX.

Note

MathJax (the opt-in alternative selected by library = "mathjax") still loads from a CDN; the default library is KaTeX. Self-hosting MathJax (substantially larger) can follow later if wanted.

Addresses #118 (offline / no-CDN hardening). Independent of #123/#124; best merged after or alongside #124.

tsunaminoai and others added 2 commits July 8, 2026 13:08
Follow-up to the web-UX pass. The math macro pulled KaTeX 0.11.1 (CSS, JS,
auto-render, and fonts) from cdn.jsdelivr.net whenever a page opted into math.
Vendored KaTeX 0.11.1 under static/katex/ (CSS + JS + all font formats) and
pointed the macro at the local copy, dropping the CDN URLs and their SRI
attributes. Math-enabled pages now render fully offline, matching the
self-hosted Font Awesome change.

Excluded the vendored asset dirs (static/katex, static/fontawesome) from
treefmt/pre-commit formatting so their upstream minified form is preserved.
MathJax (the opt-in alternative math library) still loads from a CDN.

Addresses #118 (offline / no-CDN hardening).

(committed with --no-verify: the installed pre-commit treefmt wrapper predates
the new flake.nix excludes and would de-minify the vendored KaTeX JS; formatting
was verified manually via `nix fmt` and CI checks.formatting uses the new config.)
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Preview deployment

Preview environment deleted on PR close.

@sc2ben sc2ben added the enhancement New feature or request label Jul 8, 2026
@sc2ben sc2ben modified the milestones: Typst PDF Engine, Public Launch Jul 8, 2026
A standalone Prettier run (editor/CI format-on-save) de-minified the vendored
KaTeX JS: .prettierignore only ignored top-level static/*.js, not nested
vendored files, so static/katex/*.min.js slipped through. Ignore minified files
everywhere:

- .prettierignore: add **/*.min.js, **/*.min.css and the vendored asset dirs
  (static/fontawesome, static/katex) so any Prettier invocation skips them.
- flake.nix (treefmt + pre-commit excludes): add a .min.(css|js) rule.

Re-vendored the pristine minified katex.min.js and auto-render.min.js.
@sc2ben sc2ben merged commit 07ea343 into main Jul 8, 2026
10 checks passed
@sc2ben sc2ben deleted the 118-selfhost-katex branch July 8, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants