From 11fd48f5d09596e68705169d3faa343c752b6d62 Mon Sep 17 00:00:00 2001 From: stereobooster Date: Sun, 26 Nov 2023 02:23:34 +0100 Subject: [PATCH] potential solution to screenshot --- layouts/_default/_markup/render-image.html | 10 +++++++++- layouts/partials/picture.html | 11 +++++++++-- layouts/partials/pictureDefaults.html | 3 ++- layouts/shortcodes/screenshot.html | 21 ++++++++++----------- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 2e7a5b53..7a7e18a5 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -10,9 +10,17 @@ {{ $img = resources.Get $path }} {{ end -}} +{{/* https://github.com/gohugoio/hugo/pull/10666/files */}} +{{- $params := $url.Query -}} +{{- $x2Param := $params.Get "x2" -}} +{{- $x2 := false -}} +{{- if eq $x2Param "true" -}} + {{- $x2 = true -}} +{{- end -}} +
{{- with $img -}} - {{ partial "pictureDefaults.html" (dict "img" . "alt" $altText "class" $class) }} + {{ partial "pictureDefaults.html" (dict "img" . "alt" $altText "class" $class "x2" $x2) }} {{- else -}} {{ $altText }} {{- end -}} diff --git a/layouts/partials/picture.html b/layouts/partials/picture.html index 9056f224..33553667 100644 --- a/layouts/partials/picture.html +++ b/layouts/partials/picture.html @@ -4,6 +4,7 @@ {{ $lazy := .lazy }} {{ $webp := .webp }} {{ $lqip := .lqip }} +{{ $x2 := .x2 | default false }} {{ with $img }} {{ if (eq .MediaType.SubType "svg") }} @@ -45,6 +46,12 @@ style="background-image:url(data:image/webp;base64,{{ $bg }});background-size:cover" {{ end }} > + {{ $width := .Width }} + {{ $height := .Height }} + {{ if $x2 }} + {{ $width = div .Width 2 }} + {{ $height = div .Height 2 }} + {{ end }} {{ if $webp }} {{- end -}} - {{ with .Get + + {{ $altText := "" }} + {{ with .Get "alt" }} + {{ $altText = . }} + {{ else }} + {{ $altText = (.Get "caption") | markdownify | plainify }} + {{ end }} + + {{ partial "pictureDefaults.html" (dict "img" $image "alt" $altText "x2" true) }} + {{- if .Get "href" }}{{ end -}} {{- if .Get "caption" -}}