aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/_default
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2022-10-19 05:36:58 -0400
committertdro <tdro@noreply.example.com>2022-10-19 05:36:58 -0400
commitca3f788e588def92cef7f48bfb303d0fbb269924 (patch)
tree57e02d41477a1e46fec07c9df5f5a837f9d417a0 /themes/default/layouts/_default
parentc4ecb047f4b4afd2a2ae5c536337478d86c71ad4 (diff)
downloadcanory-ca3f788e588def92cef7f48bfb303d0fbb269924.tar.gz
canory-ca3f788e588def92cef7f48bfb303d0fbb269924.tar.bz2
canory-ca3f788e588def92cef7f48bfb303d0fbb269924.zip
themes/default/layouts/_default/_markup/render-image: Add dumb orientation check
Diffstat (limited to 'themes/default/layouts/_default')
-rw-r--r--themes/default/layouts/_default/_markup/render-image.html111
1 files changed, 62 insertions, 49 deletions
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. */ -}}
<figure>
- <a href="{{ $source }}">
+ <a data-orientation="{{ $orientation }}" href="{{ $source }}">
<picture>
- {{- with $local }}
- {{- $local = .Fit (print $dimensions " webp") }}
- {{- $local = $local | resources.Copy (print (partial "function-paths.html" "media") "/" $author "/" $immutable ".webp") }}
- <source srcset="{{- $local.Permalink -}}" type="image/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 }}
+ <source srcset="{{ $srcset }}" type="image/webp" />
{{- end }}
- {{- with $cache }}
- {{- $cache = .Fit (print $dimensions " webp") }}
- {{- $cache = $cache | resources.Copy (print $author "/media/" $immutable ".webp") }}
- <source srcset="{{- $cache.Permalink -}}" type="image/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") -}}
- <source srcset="/{{- print $fileCache ".webp" -}}" type="image/webp" />
- {{- end -}}
- {{- if fileExists (print "public/" $author "/media/" $immutable ".webp") -}}
- <source srcset="/{{- print $author "/media/" $immutable ".webp" -}}" type="image/webp" />
- {{- end -}}
- {{- $width = .Width -}}
- {{- $height = .Height -}}
- {{- $cache = .Permalink }}
- {{- end -}}
<img loading="lazy"
src="{{ or $cache $source }}"
alt="{{ $.Text | htmlUnescape }}"
@@ -81,13 +98,9 @@
</picture>
</a>
<figcaption>
- {{ with $.Title -}}
- {{ . | markdownify }}
- {{ else -}}
- Image/Picture
- {{ end -}}
+ {{ $figcaption }}
<br>
- Index: {{ with $cache }} {{ print "[Cache](" . ")" | markdownify }} &middot; {{ end }}
+ Index: {{ with $cache }} {{ print "[Cache](" $cache ")" | markdownify }} &middot; {{ end }}
{{ print "[Source](" $source ")" | markdownify }}
</figcaption>
</figure>