From ad547d0f01015471dd38c8e951411e6db52d8b56 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 16 Nov 2023 16:57:38 +0000 Subject: [PATCH] Hermit-V2 Theme Update --- layouts/_default/baseof.html | 6 +- layouts/shortcodes/figure.html | 131 +++++++++++++++++++++++++-------- 2 files changed, 105 insertions(+), 32 deletions(-) diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 31ecb9a..942c426 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -17,8 +17,8 @@ {{ printf `` .Rel .MediaType.Type .Permalink $.Title | safeHTML }} {{ end -}} {{ $style := resources.Get "scss/style.scss" | resources.ExecuteAsTemplate "css/style.css" . | toCSS | minify | fingerprint -}} - -{{- range .Params.custom_css -}}{{- end -}} + +{{- range .Params.custom_css -}}{{- end -}} {{- block "head" . -}}{{- end -}} {{- if templates.Exists "partials/extra-head.html" -}}{{- partial "extra-head.html" . -}}{{- end -}} @@ -39,7 +39,7 @@ {{ $linkshare := resources.Get "js/link-share.js" | minify | fingerprint -}} {{- end -}} - {{- range .Params.custom_js -}}{{- end }} + {{- range .Params.custom_js -}}{{- end }} {{- partial "mathjax.html" . -}} {{- if templates.Exists "partials/extra-foot.html" -}}{{- partial "extra-foot.html" . -}}{{- end }} diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index 0afe081..7512c50 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -1,30 +1,103 @@ - - {{- if .Get "link" -}} - - {{- end -}} - {{ with .Get - {{- if .Get "link" }}{{ end -}} - {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}} -
- {{ with (.Get "title") -}} -

{{ . }}

- {{- end -}} - {{- if or (.Get "caption") (.Get "attr") -}}

- {{- .Get "caption" | markdownify -}} - {{- with .Get "attrlink" }} - - {{- end -}} - {{- .Get "attr" | markdownify -}} - {{- if .Get "attrlink" }}{{ end }}

+{{/* Extending upon [https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/shortcodes/figure.html] */}} +{{/* Help from [https://discourse.gohugo.io/t/has-anyone-a-webp-shortcode/35391] */}} +{{- $path := .Get "src" -}} +{{- $link := .Get "link" -}} +{{- $target := .Get "target" -}} +{{- $rel := .Get "rel" -}} +{{- $class := .Get "class" -}} +{{- $alt := .Get "alt" -}} +{{- $attr := .Get "attr" -}} +{{- $attrlink := .Get "attrlink" -}} +{{- $title := .Get "title" -}} +{{- $width := .Get "width" -}} +{{- $height := .Get "height" -}} +{{- $caption := .Get "caption" -}} +{{- $loading := .Get "loading" -}} +{{- $jpg := "" -}} +{{- $webp := "" -}} +{{- $fitOptionstojpg := printf "%vx%v jpg" $width $height -}} +{{- $fitOptionstowebp := printf "%vx%v webp" $width $height -}} + +{{- $msg1 := "The %q shortcode requires a parameter named %q. See %s" -}} +{{- $msg2 := "The resource %q passed to the %q shortcode is not an image. See %s" -}} +{{- $msg3 := "The resource %q passed to the %q shortcode could not be found. See %s" -}} + +{{- if not (findRE `http[s]{0,1}://` $path 1) -}} + + {{ 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 -}} + + + {{- if $link -}} + + {{- end -}} + + + + {{ with $alt }}{{ . }}{{ else }}{{ $caption | markdownify| plainify }}{{ end }} + + {{- if $link }}{{ end -}} + {{- if or (or $title $caption) $attr -}} +
+ {{ with $title -}}

{{ . }}

{{- end -}} + {{- if or $caption $attr -}}

+ {{- $caption | markdownify -}} + {{- with $attrlink }}{{- end -}} + {{- $attr | markdownify -}} + {{- if $attrlink }}{{ end }}

{{- end }} -
- {{- end }} - +
+ {{- end -}} + + {{- else -}} + {{- errorf $msg2 $path $.Name $.Position -}} + {{- end -}} + {{- else -}} + {{- errorf $msg3 $path .Name .Position -}} + {{- end -}} + +{{- else -}} + + {{- if $link -}}{{- end -}} + {{ with $alt }}{{ . }}{{ else }}{{ $caption | markdownify| plainify }}{{ end }} + {{- if $link }}{{ end -}} + {{- if or (or $title $caption) $attr -}} +
+ {{ with $title -}}

{{ . }}

{{- end -}} + {{- if or $caption $attr -}}

+ {{- $caption | markdownify -}} + {{- with $attrlink }}{{- end -}} + {{- $attr | markdownify -}} + {{- if $attrlink }}{{ end }}

+ {{- end }} +
+ {{- end -}} + + +{{- end -}}