mirror of https://github.com/lxndrblz/anatole.git

Alexander Bilz
4 days ago 79136dc9cd464d32ff37e90df09b97db64575f99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{{/* stylesheet */ -}}
 
{{ $cssFile := cond hugo.IsProduction "katex.min.css" "katex.css" -}}
{{ $cssUrl := printf "https://unpkg.com/katex@latest/dist/%s" $cssFile -}}
{{ with try (resources.GetRemote $cssUrl) -}}
  {{ with .Err -}}
    {{ errorf "Could not retrieve KaTeX css file from CDN. Reason: %s." . -}}
  {{ else with .Value -}}
    {{ $css := resources.Copy (printf "css/%s" $cssFile) . | resources.Fingerprint "sha512" -}}
    <link
      rel="stylesheet"
      href="{{- $css.RelPermalink -}}"
      integrity="{{- $css.Data.Integrity -}}"
      crossorigin="anonymous"
    />
  {{ end -}}
{{ end -}}
 
{{/* font files */ -}}
 
{{ $fontFiles := slice -}}
{{ $data := dict -}}
{{ $url := "https://unpkg.com/katex@latest/dist/fonts?meta" -}}
{{ with try (resources.GetRemote $url) -}}
  {{ with .Err -}}
    {{ errorf "%s" . -}}
  {{ else with ( .Value | unmarshal ) -}}
    {{ range .files -}}
      {{ $fontFiles = $fontFiles | append .path -}}
    {{ end -}}
  {{ else -}}
    {{ errorf "Unable to get remote resource %q" $url -}}
  {{ end -}}
{{ end -}}
 
{{ range $fontFile := $fontFiles -}}
  {{ $fontUrl := (printf "https://unpkg.com/katex@latest%s" $fontFile) -}}
  {{ with try (resources.GetRemote $fontUrl) -}}
    {{ with .Err -}}
      {{ errorf "Could not retrieve KaTeX font file from CDN. Reason: %s." . -}}
    {{ else with .Value -}}
      {{ with resources.Copy (printf "css/fonts/%s" (replace $fontFile "/dist/fonts/" "")) . -}}
        {{ .Publish -}}
      {{ end -}}
    {{ end -}}
  {{ end -}}
{{ end -}}