Skip to content

Commit fe22fca

Browse files
deiningchalin
authored andcommitted
Fix error when displaying formulae with latest hugo version 0.141.0
1 parent 3e9488d commit fe22fca

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

layouts/partials/scripts/katex.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
{{/* load stylesheet and scripts for KaTeX support */ -}}
44
{{ $katex_css_url := printf "https://cdn.jsdelivr.net/npm/katex@%s/dist/katex.min.css" $version -}}
5-
{{ with resources.GetRemote $katex_css_url -}}
5+
{{ with try (resources.GetRemote $katex_css_url) -}}
66
{{ with .Err -}}
77
{{ errorf "Could not retrieve KaTeX css file from CDN. Reason: %s." . -}}
8-
{{ else -}}
8+
{{ else with.Value -}}
99
{{ $secureCSS := . | resources.Fingerprint "sha512" -}}
1010
<link rel="stylesheet" href="{{- $katex_css_url -}}" integrity="{{- $secureCSS.Data.Integrity -}}" crossorigin="anonymous">
1111
{{ end -}}
@@ -15,12 +15,12 @@
1515

1616
{{/* The loading of KaTeX is deferred to speed up page rendering */ -}}
1717
{{ $katex_js_url := printf "https://cdn.jsdelivr.net/npm/katex@%s/dist/katex.min.js" $version -}}
18-
{{ with resources.GetRemote $katex_js_url -}}
18+
{{ with try (resources.GetRemote $katex_js_url) -}}
1919
{{ with .Err -}}
2020
{{ errorf "Could not retrieve KaTeX script from CDN. Reason: %s." . -}}
21-
{{ else -}}
21+
{{ else with.Value -}}
2222
{{ $secureJS := . | resources.Fingerprint "sha512" -}}
23-
<script defer src="{{- .RelPermalink -}}" integrity="{{- $secureJS.Data.Integrity -}}" crossorigin="anonymous" ></script>
23+
<script defer src="{{- .RelPermalink -}}" integrity="{{- $secureJS.Data.Integrity -}}" crossorigin="anonymous" ></script>
2424
{{ end -}}
2525
{{ else -}}
2626
{{ errorf "Invalid KaTeX version %s, could not retrieve this version from CDN." $version -}}
@@ -34,14 +34,14 @@
3434
{{/* To automatically render math in text elements, include the auto-render extension: */ -}}
3535

3636
{{ $katex_autorender_url := printf "https://cdn.jsdelivr.net/npm/katex@%s/dist/contrib/auto-render.min.js" $version -}}
37-
{{ with resources.GetRemote $katex_autorender_url -}}
37+
{{ with try (resources.GetRemote $katex_autorender_url) -}}
3838
{{ with .Err -}}
3939
{{ errorf "Could not retrieve KaTeX auto render extension from CDN. Reason: %s." . -}}
40-
{{ else -}}
40+
{{ else with .Value -}}
4141
{{ $secureJS := . | resources.Fingerprint "sha512" -}}
4242
<script defer src="{{- .RelPermalink -}}" integrity="{{- $secureJS.Data.Integrity -}}" crossorigin="anonymous"
4343
{{ 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 -}} >
44-
</script>
44+
</script>
4545
{{ end -}}
4646
{{ else -}}
4747
{{ errorf "Invalid KaTeX version %s, could not retrieve this version from CDN." $version -}}

layouts/partials/scripts/mhchem.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{{/* Add support for displaying chemical equations and physical units by loading the mhchem extension: */ -}}
22
{{ $mhchem_url := printf "https://cdn.jsdelivr.net/npm/katex@%s/dist/contrib/mhchem.min.js" .version -}}
3-
{{ with resources.GetRemote $mhchem_url -}}
3+
{{ with try (resources.GetRemote $mhchem_url) -}}
44
{{ with .Err -}}
55
{{ errorf "Could not retrieve mhchem script from CDN. Reason: %s." . -}}
6-
{{ else -}}
6+
{{ else with .Value -}}
77
{{ $secureJS := . | resources.Fingerprint "sha512" -}}
8-
<script defer src="{{- .RelPermalink -}}" integrity="{{- $secureJS.Data.Integrity -}}" crossorigin="anonymous" ></script>
8+
<script defer src="{{- .RelPermalink -}}" integrity="{{- $secureJS.Data.Integrity -}}" crossorigin="anonymous" ></script>
99
{{ end -}}
1010
{{ else -}}
1111
{{ errorf "Invalid KaTeX version %s, could not retrieve this version from CDN." .version -}}

0 commit comments

Comments
 (0)