From ca3f788e588def92cef7f48bfb303d0fbb269924 Mon Sep 17 00:00:00 2001 From: tdro Date: Wed, 19 Oct 2022 05:36:58 -0400 Subject: themes/default/layouts/_default/_markup/render-image: Add dumb orientation check --- assets/css/default.css | 9 ++ .../layouts/_default/_markup/render-image.html | 111 ++++++++++++--------- 2 files changed, 71 insertions(+), 49 deletions(-) diff --git a/assets/css/default.css b/assets/css/default.css index bffcc03..6fe3fbf 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -930,6 +930,15 @@ micro-content > figure > a { display: inline-block; } +micro-content > figure > a[data-orientation="landscape"] { + display: block; +} + +micro-content > figure > a[data-orientation="landscape"] img { + width: 100%; + max-height: 20rem; +} + micro-metadata { align-items: center; color: #444; diff --git a/themes/default/layouts/_default/_markup/render-image.html b/themes/default/layouts/_default/_markup/render-image.html index 463cc80..150ad54 100644 --- a/themes/default/layouts/_default/_markup/render-image.html +++ b/themes/default/layouts/_default/_markup/render-image.html @@ -1,15 +1,18 @@ -{{- $source := $.Destination | safeURL -}} -{{- $public := print "public/" $source -}} -{{- $local := "" -}} -{{- $cache := "" -}} -{{- $exists := "" -}} -{{- $width := "" -}} -{{- $height := "" -}} -{{- $dimensions := "600x360" -}} -{{- $author := .Page.Section -}} -{{- $relURL := strings.TrimPrefix .Page.Site.BaseURL .Page.Permalink -}} -{{- $immutable := print ($relURL | humanize | urlize) "-" ($source | sha256 | truncate 8 "") -}} -{{- $fileCache := print (partial "function-paths.html" "media") "/" $author "/" $immutable -}} +{{- $source := $.Destination | safeURL -}} +{{- $public := print "public/" $source -}} +{{- $local := "" -}} +{{- $cache := "" -}} +{{- $exists := "" -}} +{{- $width := "" -}} +{{- $height := "" -}} +{{- $srcset := "" -}} +{{- $figcaption := "Image/Picture" -}} +{{- $orientation := "landscape" -}} +{{- $dimensions := "600x360" -}} +{{- $author := .Page.Section -}} +{{- $relURL := strings.TrimPrefix .Page.Site.BaseURL .Page.Permalink -}} +{{- $immutable := print ($relURL | humanize | urlize) "-" ($source | sha256 | truncate 8 "") -}} +{{- $fileCache := print (partial "function-paths.html" "media") "/" $author "/" $immutable -}} {{- if not (and (fileExists (print "public/" $fileCache ".webp")) (fileExists (print "public/" $fileCache (path.Ext $source)))) -}} {{- with $remote := resources.GetRemote $source -}} @@ -35,42 +38,56 @@ {{- else -}} {{- $exists = resources.Get (print "public/" $fileCache (path.Ext $source)) -}} {{- $exists = $exists.Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/" (path.Base $exists)) -}} +{{- end -}} + +{{- with $local }} + {{- $local = .Fit (print $dimensions " webp") }} + {{- $local = $local | resources.Copy (print (partial "function-paths.html" "media") "/" $author "/" $immutable ".webp") }} + {{- $srcset = $local.Permalink -}} + {{- $local = .Fit $dimensions }} + {{- $local = $local | resources.Copy (print (partial "function-paths.html" "media") "/" $author "/" $immutable (path.Ext $local)) }} + {{- $width = $local.Width -}} + {{- $height = $local.Height -}} + {{- $writeToFile := $local.Permalink }} +{{- end }} + +{{- with $cache }} + {{- $cache = .Fit (print $dimensions " webp") }} + {{- $cache = $cache | resources.Copy (print $author "/media/" $immutable ".webp") }} + {{- $srcset = $cache.Permalink -}} + {{- $cache = .Fit $dimensions }} + {{- $cache = $cache | resources.Copy (print (partial "function-paths.html" "media") "/" $author "/" $immutable (path.Ext $cache)) }} + {{- $width = $cache.Width -}} + {{- $height = $cache.Height -}} + {{- $cache = $cache.Permalink }} +{{- end -}} + +{{- with $exists }} + {{- if fileExists (print "public/" $fileCache ".webp") -}} + {{- $srcset = print "/" $fileCache ".webp" -}} + {{- end -}} + {{- if fileExists (print "public/" $author "/media/" $immutable ".webp") -}} + {{- $srcset = print "/" $author "/media/" $immutable ".webp" -}} + {{- end -}} + {{- $width = .Width -}} + {{- $height = .Height -}} + {{- $cache = .Permalink }} +{{- end -}} + +{{- if lt $width $height -}} + {{- $orientation = "portrait" -}} +{{- end -}} + +{{- with $.Title -}} + {{- $figcaption = . | markdownify -}} {{ end }} {{- /* This comment removes trailing newlines and white spaces. */ -}}
- + - {{- with $local }} - {{- $local = .Fit (print $dimensions " webp") }} - {{- $local = $local | resources.Copy (print (partial "function-paths.html" "media") "/" $author "/" $immutable ".webp") }} - - {{- $local = .Fit $dimensions }} - {{- $local = $local | resources.Copy (print (partial "function-paths.html" "media") "/" $author "/" $immutable (path.Ext $local)) }} - {{- $width = $local.Width -}} - {{- $height = $local.Height -}} - {{- $writeToFile := $local.Permalink }} + {{- with $srcset }} + {{- end }} - {{- with $cache }} - {{- $cache = .Fit (print $dimensions " webp") }} - {{- $cache = $cache | resources.Copy (print $author "/media/" $immutable ".webp") }} - - {{- $cache = .Fit $dimensions }} - {{- $cache = $cache | resources.Copy (print (partial "function-paths.html" "media") "/" $author "/" $immutable (path.Ext $cache)) }} - {{- $width = $cache.Width -}} - {{- $height = $cache.Height -}} - {{- $cache = $cache.Permalink }} - {{- end -}} - {{- with $exists }} - {{- if fileExists (print "public/" $fileCache ".webp") -}} - - {{- end -}} - {{- if fileExists (print "public/" $author "/media/" $immutable ".webp") -}} - - {{- end -}} - {{- $width = .Width -}} - {{- $height = .Height -}} - {{- $cache = .Permalink }} - {{- end -}} {{ $.Text | htmlUnescape }}
- {{ with $.Title -}} - {{ . | markdownify }} - {{ else -}} - Image/Picture - {{ end -}} + {{ $figcaption }}
- Index: {{ with $cache }} {{ print "[Cache](" . ")" | markdownify }} · {{ end }} + Index: {{ with $cache }} {{ print "[Cache](" $cache ")" | markdownify }} · {{ end }} {{ print "[Source](" $source ")" | markdownify }}
-- cgit v1.2.3