aboutsummaryrefslogtreecommitdiff
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
parentc4ecb047f4b4afd2a2ae5c536337478d86c71ad4 (diff)
downloadcanory-ca3f788e588def92cef7f48bfb303d0fbb269924.tar.gz
canory-ca3f788e588def92cef7f48bfb303d0fbb269924.tar.bz2
canory-ca3f788e588def92cef7f48bfb303d0fbb269924.zip
themes/default/layouts/_default/_markup/render-image: Add dumb orientation check
-rw-r--r--assets/css/default.css9
-rw-r--r--themes/default/layouts/_default/_markup/render-image.html111
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. */ -}}
<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>