|
2 | 2 |
|
3 | 3 | {{/* load stylesheet and scripts for KaTeX support */ -}} |
4 | 4 | {{ $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) -}} |
6 | 6 | {{ with .Err -}} |
7 | 7 | {{ errorf "Could not retrieve KaTeX css file from CDN. Reason: %s." . -}} |
8 | | - {{ else -}} |
| 8 | + {{ else with.Value -}} |
9 | 9 | {{ $secureCSS := . | resources.Fingerprint "sha512" -}} |
10 | 10 | <link rel="stylesheet" href="{{- $katex_css_url -}}" integrity="{{- $secureCSS.Data.Integrity -}}" crossorigin="anonymous"> |
11 | 11 | {{ end -}} |
|
15 | 15 |
|
16 | 16 | {{/* The loading of KaTeX is deferred to speed up page rendering */ -}} |
17 | 17 | {{ $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) -}} |
19 | 19 | {{ with .Err -}} |
20 | 20 | {{ errorf "Could not retrieve KaTeX script from CDN. Reason: %s." . -}} |
21 | | - {{ else -}} |
| 21 | + {{ else with.Value -}} |
22 | 22 | {{ $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> |
24 | 24 | {{ end -}} |
25 | 25 | {{ else -}} |
26 | 26 | {{ errorf "Invalid KaTeX version %s, could not retrieve this version from CDN." $version -}} |
|
34 | 34 | {{/* To automatically render math in text elements, include the auto-render extension: */ -}} |
35 | 35 |
|
36 | 36 | {{ $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) -}} |
38 | 38 | {{ with .Err -}} |
39 | 39 | {{ errorf "Could not retrieve KaTeX auto render extension from CDN. Reason: %s." . -}} |
40 | | - {{ else -}} |
| 40 | + {{ else with .Value -}} |
41 | 41 | {{ $secureJS := . | resources.Fingerprint "sha512" -}} |
42 | 42 | <script defer src="{{- .RelPermalink -}}" integrity="{{- $secureJS.Data.Integrity -}}" crossorigin="anonymous" |
43 | 43 | {{ 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> |
45 | 45 | {{ end -}} |
46 | 46 | {{ else -}} |
47 | 47 | {{ errorf "Invalid KaTeX version %s, could not retrieve this version from CDN." $version -}} |
|
0 commit comments