Skip to content

Commit

Permalink
potential solution to screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
stereobooster committed Nov 26, 2023
1 parent 06195bc commit 954fd7f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
10 changes: 9 additions & 1 deletion layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

<figure>
{{- with $img -}}
{{ partial "pictureDefaults.html" (dict "img" . "alt" $altText "class" $class) }}
{{ partial "pictureDefaults.html" (dict "img" . "alt" $altText "class" $class "x2" $x2) }}
{{- else -}}
<img src="{{ .Destination | safeURL }}" alt="{{ $altText }}" class="{{ $class }}"/>
{{- end -}}
Expand Down
11 changes: 9 additions & 2 deletions layouts/partials/picture.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{{ $lazy := .lazy }}
{{ $webp := .webp }}
{{ $lqip := .lqip }}
{{ $x2 := .x2 | default false }}

{{ with $img }}
{{ if (eq .MediaType.SubType "svg") }}
Expand Down Expand Up @@ -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 }}
<source
{{ if lt .Width 660 }}
Expand Down Expand Up @@ -76,8 +83,8 @@
{{ end }}
<img
src="{{ .RelPermalink }}"
width="{{ .Width }}"
height="{{ .Height }}"
width="{{ $width }}"
height="{{ $height }}"
{{ with $class }} class="{{ . }}" {{ end }}
{{ with $alt }} alt="{{ . }}" {{ end }}
{{ with $lazy }} loading="lazy" decoding="async" {{ end }}
Expand Down
3 changes: 2 additions & 1 deletion layouts/partials/pictureDefaults.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
{{ $lazy := $.Page.Site.Params.enableImageLazyLoading | default true }}
{{ $webp := $.Page.Site.Params.enableImageWebp | default true }}
{{ $lqip := false }}
{{ partial "picture.html" (dict "img" $img "alt" $alt "class" $class "lazy" $lazy "webp" $webp "lqip" $lqip) }}
{{ $x2 := .x2 }}
{{ partial "picture.html" (dict "img" $img "alt" $alt "class" $class "lazy" $lazy "webp" $webp "lqip" $lqip "x2" $x2) }}
21 changes: 10 additions & 11 deletions layouts/shortcodes/screenshot.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
{{- if .Get "href" -}}
<a href="{{ .Get "href" }}">
{{- end -}}
<img src="{{ $image.RelPermalink }}"
{{- if or (.Get "alt") (.Get "caption") }}
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify | plainify }}{{ end }}"
{{- end -}}
{{ if .Site.Params.enableImageLazyLoading | default true }}
loading="lazy"
{{ end }}
width="100%"
height="auto"
style="max-width:{{ div $image.Width 2 }}px; max-height:{{ div $image.Height 2 }}px;"
/>

{{ $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" }}</a>{{ end -}}
{{- if .Get "caption" -}}
<figcaption>
Expand Down

0 comments on commit 954fd7f

Please sign in to comment.