aboutsummaryrefslogtreecommitdiff
path: root/themes
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2023-02-13 18:36:40 -0500
committertdro <tdro@noreply.example.com>2023-02-13 20:15:44 -0500
commit0ff6cdf8550ab1b36e42988048460665094b0d65 (patch)
treef85ad54f389dcbdf5c54fa141f7e9fbadbe71df9 /themes
parent873195a39e84bccd8d0fafe26d6f60983f54ed0a (diff)
downloadcanory-0ff6cdf8550ab1b36e42988048460665094b0d65.tar.gz
canory-0ff6cdf8550ab1b36e42988048460665094b0d65.tar.bz2
canory-0ff6cdf8550ab1b36e42988048460665094b0d65.zip
themes/default/layouts/partials/gallery-walk: Walk with findRE
Diffstat (limited to 'themes')
-rw-r--r--themes/default/layouts/_default/section.gallery.html9
-rw-r--r--themes/default/layouts/_default/section.media.html2
-rw-r--r--themes/default/layouts/partials/gallery-walk.html96
-rw-r--r--themes/default/layouts/partials/gallery.html13
4 files changed, 47 insertions, 73 deletions
diff --git a/themes/default/layouts/_default/section.gallery.html b/themes/default/layouts/_default/section.gallery.html
index 276ae9c..dfa141e 100644
--- a/themes/default/layouts/_default/section.gallery.html
+++ b/themes/default/layouts/_default/section.gallery.html
@@ -1,8 +1 @@
-{{- $folder := print "public/" .Section "/media/" -}}
-
-{{- partial "gallery-walk.html"
- (dict
- "Folder" $folder
- "Context" .
- )
--}}
+{{- partial "gallery-walk.html" . -}}
diff --git a/themes/default/layouts/_default/section.media.html b/themes/default/layouts/_default/section.media.html
index 3bfaf58..9191a3e 100644
--- a/themes/default/layouts/_default/section.media.html
+++ b/themes/default/layouts/_default/section.media.html
@@ -38,7 +38,7 @@
{{ $count := 0 }}
{{ $result := false }}
- {{ range .Site.Pages }}
+ {{ range .Site.RegularPages }}
{{ if or
(in .Content "<figure>")
(in .Content "<imgur-video>")
diff --git a/themes/default/layouts/partials/gallery-walk.html b/themes/default/layouts/partials/gallery-walk.html
index c17b0da..6c2206f 100644
--- a/themes/default/layouts/partials/gallery-walk.html
+++ b/themes/default/layouts/partials/gallery-walk.html
@@ -1,8 +1,5 @@
-{{- $folder := .Folder -}}
-{{- $files := slice -}}
-{{- $dimensions := "320x320" -}}
-{{- $author := strings.TrimPrefix "public/" (strings.TrimSuffix "/media/" $folder) -}}
-{{- $prefix := print (partial "function-paths.html" "media") "/" $author "/gallery-walker_" -}}
+{{- $data := slice -}}
+{{- $author := partial "function-authors-data.html" . -}}
{{- $mimes := slice
"image/apng"
@@ -14,60 +11,45 @@
"image/webp"
-}}
-{{- if fileExists $folder -}}
- {{- range readDir $folder -}}
- {{- 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 -}}
+{{- range (where .Site.RegularPages "Params.Author" $author.user) -}}
+ {{- if in .Content "<figure>" -}}
+ {{- $data = $data | append (dict
+ "alt" (delimit (findRE `(?sU)alt=".*"` .Content 1) "")
+ "height" (delimit (findRE `(?sU)height=".*"` .Content 1) "")
+ "src" (delimit (findRE `(?sU)src=".*"` .Content 1) "")
+ "srcset" (delimit (findRE `(?sU)srcset=".*"` .Content 1) "")
+ "style" (delimit (findRE `(?sU)style=".*"` .Content 1) "")
+ "title" (delimit (findRE `(?sU)title=".*"` .Content 1) "")
+ "type" (delimit (findRE `(?sU)type=".*"` .Content 1) "")
+ "width" (delimit (findRE `(?sU)width=".*"` .Content 1) "")
+ "relatedHref" .Permalink
+ )
+ -}}
+ {{- end -}}
+ {{- if eq (len $data) 6 -}}
+ {{- break -}}
{{- end -}}
{{- end -}}
-{{- 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/") -}}
-
- {{- if not $relatedPage -}}
- {{- $decodedURL = print "/" $author "/" -}}
- {{- 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 }}"
- {{ printf `style="` | safeHTMLAttr -}}
- {{- partial "styles-image-gradient.html" $image.Colors | safeHTMLAttr -}}
- {{- printf `"` | safeHTMLAttr }}
- />
- </picture>
- </a>
- {{- end -}}
- {{- end -}}
- {{- end -}}
+{{- if $data -}}
+ {{- range $image := $data }}
+ <a href="{{ $image.relatedHref }}">
+ <picture>
+ <source
+ {{ $image.srcset | safeHTMLAttr }}
+ {{ $image.type | safeHTMLAttr }}
+ />
+ <img
+ loading="lazy"
+ {{ $image.alt | safeHTMLAttr }}
+ {{ $image.title | safeHTMLAttr }}
+ {{ $image.width | safeHTMLAttr }}
+ {{ $image.height | safeHTMLAttr }}
+ {{ $image.src | safeHTMLAttr }}
+ {{ $image.style | safeHTMLAttr }}
+ />
+ </picture>
+ </a>
+ {{ end }}
<gallery-overlay></gallery-overlay>
-{{- else -}}
- <footer>
- <code>No media found!</code>
- </footer>
{{- end -}}
diff --git a/themes/default/layouts/partials/gallery.html b/themes/default/layouts/partials/gallery.html
index 2634b68..8aaa2c8 100644
--- a/themes/default/layouts/partials/gallery.html
+++ b/themes/default/layouts/partials/gallery.html
@@ -1,15 +1,14 @@
-{{- $folder := print "public/" .Section "/media/" -}}
{{- $gallery := print "public/" .Section "/gallery.html" -}}
<gallery-images>
<h1>Gallery</h1>
<aside>
- {{ if fileExists $gallery }}
+ {{- if fileExists $gallery -}}
{{- (resources.Get $gallery).Content | safeHTML -}}
- {{ else }}
- <footer>
- <code>No media found!</code>
- </footer>
- {{ end }}
+ {{- else -}}
+ <footer>
+ <code>No media found!</code>
+ </footer>
+ {{- end -}}
</aside>
</gallery-images>