aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2022-12-12 00:29:03 -0500
committertdro <tdro@noreply.example.com>2022-12-12 00:29:03 -0500
commit2b7fb5cb0210ab85e4d355eabde798a785ec9c18 (patch)
tree8636ba395650c4343a23c0512e933f53cf8b8eba
parent460934b8fbd02f1907183915d380ff61d011381a (diff)
downloadcanory-2b7fb5cb0210ab85e4d355eabde798a785ec9c18.tar.gz
canory-2b7fb5cb0210ab85e4d355eabde798a785ec9c18.tar.bz2
canory-2b7fb5cb0210ab85e4d355eabde798a785ec9c18.zip
themes/default/layouts/partials/gallery-walk: Use mime types
Try to avoid nil explosion with mime type guards/checks
-rw-r--r--themes/default/layouts/partials/gallery-images.html2
-rw-r--r--themes/default/layouts/partials/gallery-walk.html103
2 files changed, 48 insertions, 57 deletions
diff --git a/themes/default/layouts/partials/gallery-images.html b/themes/default/layouts/partials/gallery-images.html
index a66531a..5950637 100644
--- a/themes/default/layouts/partials/gallery-images.html
+++ b/themes/default/layouts/partials/gallery-images.html
@@ -1,7 +1,7 @@
{{ $folder := print "public/" (partial "author-user.html" .) "/media/" }}
<gallery-images>
- <h1>Picture Gallery</h1>
+ <h1>Gallery</h1>
<aside>
{{ partial "gallery-walk.html"
(dict
diff --git a/themes/default/layouts/partials/gallery-walk.html b/themes/default/layouts/partials/gallery-walk.html
index 764fa6d..72b587c 100644
--- a/themes/default/layouts/partials/gallery-walk.html
+++ b/themes/default/layouts/partials/gallery-walk.html
@@ -4,76 +4,67 @@
{{- $author := strings.TrimPrefix "public/" (strings.TrimSuffix "/media/" $folder) -}}
{{- $prefix := print (partial "function-paths.html" "media") "/" $author "/gallery-walker_" -}}
+{{- $mimes := slice
+ "image/apng"
+ "image/avif"
+ "image/gif"
+ "image/jpeg"
+ "image/png"
+ "image/svg+xml"
+ "image/webp"
+-}}
+
{{- if fileExists $folder -}}
{{- range readDir $folder -}}
-
- {{- $name := index (split .Name ".") 0 -}}
- {{- $extension := path.Ext .Name -}}
-
- {{- if or
- (eq $extension ".apng")
- (eq $extension ".avif")
- (eq $extension ".gif")
- (eq $extension ".jfif")
- (eq $extension ".jpeg")
- (eq $extension ".jpg")
- (eq $extension ".pjp")
- (eq $extension ".pjpeg")
- (eq $extension ".png")
- (eq $extension ".svg")
- (eq $extension ".webp")
- -}}
- {{-
- $files = $files | append (dict
- "Name" .Name
- "Path" (path.Join $folder .Name)
- )
- -}}
+ {{- if not .IsDir -}}
+ {{- $file := path.Join $folder .Name -}}
+ {{- with resources.Get $file -}}
+ {{- if in $mimes (string .MediaType) -}}
+ {{-
+ $files = $files | append (dict
+ "Path" .Name
+ )
+ -}}
+ {{- end -}}
+ {{- end -}}
{{- end -}}
-
{{- if eq (len $files) 6 -}}
{{- break -}}
{{- end -}}
{{- end -}}
+{{- end -}}
- {{- if $files -}}
+{{- if and $files (resources.Get (index (first 1 $files) 0).Path) -}}
+ {{- range $files -}}
+ {{- with $image := resources.Get .Path -}}
+ {{- if in $mimes (string .MediaType) -}}
+ {{- $srcset := (.Content | resources.FromString (print $prefix (path.Base .))).Fit (print $dimensions " webp") -}}
+ {{- $image = (.Content | resources.FromString (print $prefix (path.Base .))).Fit (print $dimensions " png") -}}
+ {{- $decodedURL := print "/" (replaceRE "-" "/" (path.Base .Name) 2 | replaceRE "-.........webp" "") "/" -}}
+ {{- $relatedPage := or (in $decodedURL "/messages/") (in $decodedURL "/feeds/") -}}
- {{- range $files -}}
- {{- with $image := resources.Get .Path -}}
+ {{- if not $relatedPage -}}
+ {{- $decodedURL = print "/" $author "/" -}}
+ {{- end -}}
- {{- $srcset := (.Content | resources.FromString (print $prefix (path.Base .))).Fit (print $dimensions " webp") -}}
- {{- $image = (.Content | resources.FromString (print $prefix (path.Base .))).Fit (print $dimensions " png") -}}
- {{- $decodedURL := print "/" (replaceRE "-" "/" (path.Base .Name) 2 | replaceRE "-.........webp" "") "/" -}}
- {{- $relatedPage := or (in $decodedURL "/messages/") (in $decodedURL "/feeds/") -}}
-
- {{- if not $relatedPage -}}
- {{- $decodedURL = print "/" $author "/" -}}
+ <a href="{{ $decodedURL }}">
+ <picture>
+ <source srcset="{{ $srcset.RelPermalink }}" type="image/webp" />
+ <img loading="lazy"
+ alt="{{ .Name }}"
+ title="{{ .Name }}"
+ width="{{ $image.Width }}"
+ height="{{ $image.Height }}"
+ src="{{ $image.RelPermalink }}"
+ />
+ </picture>
+ </a>
{{- end -}}
-
- <a href="{{ $decodedURL }}">
- <picture>
- <source srcset="{{ $srcset.RelPermalink }}" type="image/webp" />
- <img loading="lazy"
- alt="{{ .Name }}"
- title="{{ .Name }}"
- width="{{ $image.Width }}"
- height="{{ $image.Height }}"
- src="{{ $image.RelPermalink }}"
- />
- </picture>
- </a>
- {{- end -}}
{{- end -}}
-
- <gallery-overlay></gallery-overlay>
-
- {{- else -}}
- <footer>
- <code>No media found!</code>
- </footer>
{{- end -}}
+ <gallery-overlay></gallery-overlay>
{{- else -}}
<footer>
<code>No media found!</code>
</footer>
-{{- end }}
+{{- end -}}