Hermit-V2 Theme Update

This commit is contained in:
GitHub Action 2023-11-16 16:57:38 +00:00
parent c6cbddfcd8
commit ad547d0f01
2 changed files with 105 additions and 32 deletions

View file

@ -17,8 +17,8 @@
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Title | safeHTML }} {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Title | safeHTML }}
{{ end -}} {{ end -}}
{{ $style := resources.Get "scss/style.scss" | resources.ExecuteAsTemplate "css/style.css" . | toCSS | minify | fingerprint -}} {{ $style := resources.Get "scss/style.scss" | resources.ExecuteAsTemplate "css/style.css" . | toCSS | minify | fingerprint -}}
<link rel="stylesheet" href="{{ $style.Permalink }}" {{ printf "integrity=%q" $style.Data.Integrity | safeHTMLAttr }} crossorigin="anonymous"> <link rel="stylesheet preload prefetch" as="style" href="{{ $style.Permalink }}" {{ printf "integrity=%q" $style.Data.Integrity | safeHTMLAttr }} crossorigin="anonymous">
{{- range .Params.custom_css -}}<link rel="stylesheet" href="{{ . | absURL }}">{{- end -}} {{- range .Params.custom_css -}}<link rel="stylesheet preload prefetch" as="style" href="{{ . | absURL }}">{{- end -}}
{{- block "head" . -}}{{- end -}} {{- block "head" . -}}{{- end -}}
{{- if templates.Exists "partials/extra-head.html" -}}{{- partial "extra-head.html" . -}}{{- end -}}</head> {{- if templates.Exists "partials/extra-head.html" -}}{{- partial "extra-head.html" . -}}{{- end -}}</head>
<body id="page"> <body id="page">
@ -39,7 +39,7 @@
{{ $linkshare := resources.Get "js/link-share.js" | minify | fingerprint -}} {{ $linkshare := resources.Get "js/link-share.js" | minify | fingerprint -}}
<script async src="{{ $linkshare.Permalink }}" {{ printf "integrity=%q" $linkshare.Data.Integrity | safeHTMLAttr }} crossorigin="anonymous"></script> <script async src="{{ $linkshare.Permalink }}" {{ printf "integrity=%q" $linkshare.Data.Integrity | safeHTMLAttr }} crossorigin="anonymous"></script>
{{- end -}} {{- end -}}
{{- range .Params.custom_js -}}<script type="text/javascript" src="{{ . | absURL }}"></script>{{- end }} {{- range .Params.custom_js -}}<script async type="text/javascript" src="{{ . | absURL }}"></script>{{- end }}
{{- partial "mathjax.html" . -}} {{- partial "mathjax.html" . -}}
{{- if templates.Exists "partials/extra-foot.html" -}}{{- partial "extra-foot.html" . -}}{{- end }} {{- if templates.Exists "partials/extra-foot.html" -}}{{- partial "extra-foot.html" . -}}{{- end }}
</body> </body>

View file

@ -1,30 +1,103 @@
<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}> {{/* Extending upon [https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/shortcodes/figure.html] */}}
{{- if .Get "link" -}} {{/* Help from [https://discourse.gohugo.io/t/has-anyone-a-webp-shortcode/35391] */}}
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}> {{- $path := .Get "src" -}}
{{- end -}} {{- $link := .Get "link" -}}
<img src="{{ .Get "src" }}" {{- $target := .Get "target" -}}
{{- if or (.Get "alt") (.Get "caption") }} {{- $rel := .Get "rel" -}}
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}" {{- $class := .Get "class" -}}
{{- end -}} {{- $alt := .Get "alt" -}}
{{- with .Get "width" }} width="{{ . }}"{{ end -}} {{- $attr := .Get "attr" -}}
{{- with .Get "height" }} height="{{ . }}"{{ end -}} {{- $attrlink := .Get "attrlink" -}}
{{- with .Get "loading" }} loading="{{ . }}"{{ end -}} {{- $title := .Get "title" -}}
loading="lazy" {{- $width := .Get "width" -}}
/><!-- Closing img tag --> {{- $height := .Get "height" -}}
{{- if .Get "link" }}</a>{{ end -}} {{- $caption := .Get "caption" -}}
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}} {{- $loading := .Get "loading" -}}
<figcaption> {{- $jpg := "" -}}
{{ with (.Get "title") -}} {{- $webp := "" -}}
<h4>{{ . }}</h4> {{- $fitOptionstojpg := printf "%vx%v jpg" $width $height -}}
{{- end -}} {{- $fitOptionstowebp := printf "%vx%v webp" $width $height -}}
{{- if or (.Get "caption") (.Get "attr") -}}<p>
{{- .Get "caption" | markdownify -}} {{- $msg1 := "The %q shortcode requires a parameter named %q. See %s" -}}
{{- with .Get "attrlink" }} {{- $msg2 := "The resource %q passed to the %q shortcode is not an image. See %s" -}}
<a href="{{ . }}"> {{- $msg3 := "The resource %q passed to the %q shortcode could not be found. See %s" -}}
{{- end -}}
{{- .Get "attr" | markdownify -}} {{- if not (findRE `http[s]{0,1}://` $path 1) -}}
{{- if .Get "attrlink" }}</a>{{ end }}</p>
{{ if not $path }}
{{ errorf $msg1 .Name "path" .Position }}
{{ end }}
{{- with $i := resources.Get $path -}}
{{- if eq $i.MediaType.MainType "image" -}}
{{- if not $width -}}{{- $width = $i.Width -}}{{- end -}}
{{- if not $height -}}{{- $height = $i.Height -}}{{- end -}}
{{- if eq $i.MediaType "image/webp" -}}
{{- $jpg = $i.Fit $fitOptionstojpg -}}
{{- $webp = $i -}}
{{- else if eq $i.MediaType "image/jpeg" -}}
{{- $webp = $i.Fit $fitOptionstowebp -}}
{{- $jpg = $i -}}
{{- else -}}
{{- $fitOptions := printf "%vx%v jpg" $width $height -}}{{- $jpg = $i.Fit $fitOptions -}}
{{- $fitOptions = printf "%vx%v webp" $width $height -}}{{- $webp = $i.Fit $fitOptions -}}
{{- end -}}
<figure{{ with $class }} class="{{ . }}" {{ end }}>
{{- if $link -}}
<a href="{{ $link }}"{{ with $target }} target="{{ . }}"{{ end }}{{ with $rel }} rel="{{ . }}"{{ end }}>
{{- end -}}
<picture>
<source srcset="{{ $webp.RelPermalink }}" type="image/webp">
<source srcset="{{ $jpg.RelPermalink }}" type="image/jpeg">
<img src="{{ $webp.RelPermalink }}"
{{- if or $alt $caption -}} alt="{{ with $alt }}{{ . }}{{ else }}{{ $caption | markdownify| plainify }}{{ end }}" {{- end -}}
{{- with $jpg.Width }} width="{{ . }}" {{ end -}}
{{- with $jpg.Height }} height="{{ . }}" {{ end -}}
{{- with $loading }} loading="{{ . }}" {{ end -}} />
</picture>
{{- if $link }}</a>{{ end -}}
{{- if or (or $title $caption) $attr -}}
<figcaption>
{{ with $title -}}<h4>{{ . }}</h4>{{- end -}}
{{- if or $caption $attr -}}<p>
{{- $caption | markdownify -}}
{{- with $attrlink }}<a href="{{ . }}">{{- end -}}
{{- $attr | markdownify -}}
{{- if $attrlink }}</a>{{ end }}</p>
{{- end }} {{- end }}
</figcaption> </figcaption>
{{- end }} {{- end -}}
</figure> </figure>
{{- else -}}
{{- errorf $msg2 $path $.Name $.Position -}}
{{- end -}}
{{- else -}}
{{- errorf $msg3 $path .Name .Position -}}
{{- end -}}
{{- else -}}
<figure{{ with $class }} class="{{ . }}" {{ end }}>
{{- if $link -}}<a href="{{ $link }}"{{ with $target }} target="{{ . }}"{{ end }}{{ with $rel }} rel="{{ . }}"{{ end }}>{{- end -}}
<img src="{{ $path }}"
{{- if or $alt $caption -}} alt="{{ with $alt }}{{ . }}{{ else }}{{ $caption | markdownify| plainify }}{{ end }}" {{- end -}}
{{- with $width }} width="{{ . }}" {{ end -}}
{{- with $height }} height="{{ . }}" {{ end -}}
{{- with $loading }} loading="{{ . }}" {{ end -}} />
{{- if $link }}</a>{{ end -}}
{{- if or (or $title $caption) $attr -}}
<figcaption>
{{ with $title -}}<h4>{{ . }}</h4>{{- end -}}
{{- if or $caption $attr -}}<p>
{{- $caption | markdownify -}}
{{- with $attrlink }}<a href="{{ . }}">{{- end -}}
{{- $attr | markdownify -}}
{{- if $attrlink }}</a>{{ end }}</p>
{{- end }}
</figcaption>
{{- end -}}
</figure>
{{- end -}}