markdown: math set by KaTeX, fetched only when a page has some

$x^2$ inline, $$…$$ for display, and a ```math block, the way GitHub
writes them, in documents, shared pages and .md files alike. KaTeX loads
on first use; until then the math shows as its source. Only the woff2
fonts are bundled.
This commit is contained in:
nvrl committed 2026-10-20 10:25:26 +02:00
1 parent 889f99f8d6
commit fc593e6452
9 files changed
+111 -6

No files matched your search

+15 -1
View File
@@ -1,8 +1,22 @@
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import type { Plugin } from 'vite'
/*
* KaTeX lists each font as woff2, woff and ttf. Every browser the app runs in
* takes woff2, and the other two would be another megabyte in the binary.
*/
const katexWoff2Only: Plugin = {
name: 'katex-woff2-only',
enforce: 'pre',
transform(code, id) {
if (!/katex(\.min)?\.css$/.test(id)) return
return code.replace(/,\s*url\([^)]*\.(?:woff|ttf)\)\s*format\("(?:woff|truetype)"\)/g, '')
},
}
export default defineConfig({
plugins: [svelte()],
plugins: [svelte(), katexWoff2Only],
build: { target: 'es2022', chunkSizeWarningLimit: 900 },
server: {
port: 4243,