From 1f88cff7d4c7de25901acbd188ab736cb9bea0e5 Mon Sep 17 00:00:00 2001 From: Justin Chen Date: Fri, 4 Apr 2025 07:07:12 +0800 Subject: [PATCH] fix: KaTeX fonts are not fetched from CDN (#656) --- layouts/partials/head.html | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 0cfc083..a1f4954 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -63,12 +63,17 @@ {{ $noop := .WordCount -}} {{ if .Page.Store.Get "hasMath" -}} - {{ $katexCssUrl := printf "https://cdn.jsdelivr.net/npm/katex@latest/dist/katex%s.css" (cond hugo.IsProduction ".min" "") -}} + {{ $katexBaseUrl := "https://cdn.jsdelivr.net/npm/katex@latest/dist" }} + {{ $katexCssUrl := printf "%s/katex%s.css" $katexBaseUrl (cond hugo.IsProduction ".min" "") -}} + {{ $katexFontPattern := "url(fonts/" }} + {{ $katexFontSubstituted := printf "url(%s/fonts/" $katexBaseUrl }} + {{ with try (resources.GetRemote $katexCssUrl) -}} {{ with .Err -}} {{ errorf "Could not retrieve KaTeX css file from %s. Reason: %s." $katexCssUrl . -}} {{ else with.Value -}} - {{ with resources.Copy (printf "css/katex%s.css" (cond hugo.IsProduction ".min" "")) . -}} + {{ $katexCssContent := strings.Replace .Content $katexFontPattern $katexFontSubstituted }} + {{ with resources.FromString (printf "css/katex%s.css" (cond hugo.IsProduction ".min" "")) $katexCssContent -}} {{ end -}} {{ end -}}