Skip to content

Commit

Permalink
Fix error when displaying formulae with latest hugo version 0.141.0
Browse files Browse the repository at this point in the history
  • Loading branch information
deining authored and chalin committed Jan 24, 2025
1 parent 552475d commit 41d4894
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions layouts/partials/scripts/katex.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" -}}
<link rel="stylesheet" href="{{- $katex_css_url -}}" integrity="{{- $secureCSS.Data.Integrity -}}" crossorigin="anonymous">
{{ end -}}
Expand All @@ -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" -}}
<script defer src="{{- .RelPermalink -}}" integrity="{{- $secureJS.Data.Integrity -}}" crossorigin="anonymous" ></script>
<script defer src="{{- .RelPermalink -}}" integrity="{{- $secureJS.Data.Integrity -}}" crossorigin="anonymous" ></script>
{{ end -}}
{{ else -}}
{{ errorf "Invalid KaTeX version %s, could not retrieve this version from CDN." $version -}}
Expand All @@ -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" -}}
<script defer src="{{- .RelPermalink -}}" integrity="{{- $secureJS.Data.Integrity -}}" crossorigin="anonymous"
{{ printf "onload='renderMathInElement(%s, %s);'" (( $.Page.Site.Params.katex.html_dom_element | default "document.body" ) | safeJS ) ( printf "%s" ( $.Page.Site.Params.katex.options | jsonify )) | safeHTMLAttr -}} >
</script>
</script>
{{ end -}}
{{ else -}}
{{ errorf "Invalid KaTeX version %s, could not retrieve this version from CDN." $version -}}
Expand Down
6 changes: 3 additions & 3 deletions layouts/partials/scripts/mhchem.html
Original file line number Diff line number Diff line change
@@ -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" -}}
<script defer src="{{- .RelPermalink -}}" integrity="{{- $secureJS.Data.Integrity -}}" crossorigin="anonymous" ></script>
<script defer src="{{- .RelPermalink -}}" integrity="{{- $secureJS.Data.Integrity -}}" crossorigin="anonymous" ></script>
{{ end -}}
{{ else -}}
{{ errorf "Invalid KaTeX version %s, could not retrieve this version from CDN." .version -}}
Expand Down

0 comments on commit 41d4894

Please sign in to comment.