From 41d489423e8bb722277074fb34987f971bb7d3b1 Mon Sep 17 00:00:00 2001 From: Andreas Deininger Date: Tue, 21 Jan 2025 22:47:13 +0100 Subject: [PATCH] Fix error when displaying formulae with latest hugo version 0.141.0 --- layouts/partials/scripts/katex.html | 16 ++++++++-------- layouts/partials/scripts/mhchem.html | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/layouts/partials/scripts/katex.html b/layouts/partials/scripts/katex.html index 708b026fb6..a932cf7bc0 100644 --- a/layouts/partials/scripts/katex.html +++ b/layouts/partials/scripts/katex.html @@ -2,10 +2,10 @@ {{/* load stylesheet and scripts for KaTeX support */ -}} {{ $katex_css_url := printf "https://cdn.jsdelivr.net/npm/katex@%s/dist/katex.min.css" $version -}} -{{ with resources.GetRemote $katex_css_url -}} +{{ with try (resources.GetRemote $katex_css_url) -}} {{ with .Err -}} {{ errorf "Could not retrieve KaTeX css file from CDN. Reason: %s." . -}} - {{ else -}} + {{ else with.Value -}} {{ $secureCSS := . | resources.Fingerprint "sha512" -}} {{ end -}} @@ -15,12 +15,12 @@ {{/* The loading of KaTeX is deferred to speed up page rendering */ -}} {{ $katex_js_url := printf "https://cdn.jsdelivr.net/npm/katex@%s/dist/katex.min.js" $version -}} -{{ with resources.GetRemote $katex_js_url -}} +{{ with try (resources.GetRemote $katex_js_url) -}} {{ with .Err -}} {{ errorf "Could not retrieve KaTeX script from CDN. Reason: %s." . -}} - {{ else -}} + {{ else with.Value -}} {{ $secureJS := . | resources.Fingerprint "sha512" -}} - + {{ end -}} {{ else -}} {{ errorf "Invalid KaTeX version %s, could not retrieve this version from CDN." $version -}} @@ -34,14 +34,14 @@ {{/* To automatically render math in text elements, include the auto-render extension: */ -}} {{ $katex_autorender_url := printf "https://cdn.jsdelivr.net/npm/katex@%s/dist/contrib/auto-render.min.js" $version -}} -{{ with resources.GetRemote $katex_autorender_url -}} +{{ with try (resources.GetRemote $katex_autorender_url) -}} {{ with .Err -}} {{ errorf "Could not retrieve KaTeX auto render extension from CDN. Reason: %s." . -}} - {{ else -}} + {{ else with .Value -}} {{ $secureJS := . | resources.Fingerprint "sha512" -}} + {{ end -}} {{ else -}} {{ errorf "Invalid KaTeX version %s, could not retrieve this version from CDN." $version -}} diff --git a/layouts/partials/scripts/mhchem.html b/layouts/partials/scripts/mhchem.html index 45c0198800..d0eff790a5 100644 --- a/layouts/partials/scripts/mhchem.html +++ b/layouts/partials/scripts/mhchem.html @@ -1,11 +1,11 @@ {{/* Add support for displaying chemical equations and physical units by loading the mhchem extension: */ -}} {{ $mhchem_url := printf "https://cdn.jsdelivr.net/npm/katex@%s/dist/contrib/mhchem.min.js" .version -}} -{{ with resources.GetRemote $mhchem_url -}} +{{ with try (resources.GetRemote $mhchem_url) -}} {{ with .Err -}} {{ errorf "Could not retrieve mhchem script from CDN. Reason: %s." . -}} - {{ else -}} + {{ else with .Value -}} {{ $secureJS := . | resources.Fingerprint "sha512" -}} - + {{ end -}} {{ else -}} {{ errorf "Invalid KaTeX version %s, could not retrieve this version from CDN." .version -}}