From 52cb4b7a7029ec36389afab3b762728a6942d0b2 Mon Sep 17 00:00:00 2001
From: Andreas Deininger <andreas@deininger.net>
Date: Sat, 07 Jun 2025 13:03:09 +0000
Subject: [PATCH] chore: server side rendering of math equations (#543)
---
layouts/partials/head.html | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 6622bc0..c3f8f3c 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -230,4 +230,20 @@
<!-- Schema.org-->
{{ partial "schema.html" . }}
+
+ <!-- KaTeX-->
+ {{ $noop := .WordCount }}
+ {{ if .Page.Store.Get "hasMath" }}
+ {{ $katex_css_url := printf "https://cdn.jsdelivr.net/npm/katex@latest/dist/katex%s.css" (cond hugo.IsProduction ".min" "") -}}
+ {{ with try (resources.GetRemote $katex_css_url) -}}
+ {{ with .Err -}}
+ {{ errorf "Could not retrieve KaTeX css file from CDN. Reason: %s." . -}}
+ {{ else with.Value -}}
+ {{ with resources.Copy (printf "css/katex%s.css" (cond hugo.IsProduction ".min" "")) . }}
+ {{ $secureCSS := . | resources.Fingerprint "sha512" -}}
+<link rel="stylesheet" href="{{- .RelPermalink -}}" integrity="{{- $secureCSS.Data.Integrity -}}" crossorigin="anonymous">
+ {{ end -}}
+ {{ end -}}
+ {{ end -}}
+ {{ end }}
</head>
--
Gitblit v1.10.0