diff options
author | tdro <tdro@noreply.example.com> | 2022-08-28 00:08:03 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-08-28 00:08:03 -0400 |
commit | 5c08d7666c3b4f75207822344edb7f54e1c4b0cb (patch) | |
tree | cd180a073bc1988cfb99f7982e74a4d833164e31 /themes | |
parent | b77c159ae5cfc45e7fd80457e840e769fc97b555 (diff) | |
download | canory-5c08d7666c3b4f75207822344edb7f54e1c4b0cb.tar.gz canory-5c08d7666c3b4f75207822344edb7f54e1c4b0cb.tar.bz2 canory-5c08d7666c3b4f75207822344edb7f54e1c4b0cb.zip |
themes/default/layouts/partials/function-caches-images: Merge alternate copy properties
Compensate for fit and resize. Set images from user profile configuration.
Diffstat (limited to 'themes')
6 files changed, 142 insertions, 137 deletions
diff --git a/themes/default/layouts/partials/author-card.html b/themes/default/layouts/partials/author-card.html index 7c88dfb..953f833 100644 --- a/themes/default/layouts/partials/author-card.html +++ b/themes/default/layouts/partials/author-card.html @@ -1,42 +1,56 @@ -{{- $path := print "public/" .Data.user "/media/profile/picture.png" -}} -{{- $image := resources.Get $path -}} -{{- $dimensions := "96x96" -}} -{{- $404image := resources.Get "data/media/404.png" -}} +{{- $profile := .Data.picture.profile -}} + +{{- $image := partial "function-caches-images.html" + (dict + "Source" (print .Data.user "/" $profile) + "Fit" "160x160" + "Target" (print (partial "function-paths.html" "media") "/" .Data.user "/") + "Copy" (print (partial "function-paths.html" "media") "/" .Data.user "/" (path.Base $profile)) + "OptimizedCopy" (print (partial "function-paths.html" "media") "/" .Data.user "/" (path.BaseName $profile) ".webp") + ) +-}} + +{{- $width := $image.Width -}} +{{- $height := $image.Height -}} +{{- $source := $image.RelPermalink -}} +{{- $alternate := .Data.name -}} +{{- $sourceset := $image.OptRelPermalink -}} + +{{- with .Params.feed.image -}} + {{- $width = "64" -}} + {{- $height = "64" -}} + {{- $source = $.Params.feed.image -}} + {{- $alternate = $.Params.feed.name -}} +{{- end -}} <micro-author> <micro-card> <micro-summary> - <micro-thumbnail> - <figure> - <a title="{{ .Data.name }}" href="{{ "" | absURL }}/{{ .Data.user }}/#"> - <picture> - {{- with $image }} - {{- $image = .Content | resources.FromString (print (partial "function-paths.html" "media") "/" $.Data.user "/" (path.Base .)) }} - <source srcset="{{- ($image.Fit (print $dimensions " webp")).RelPermalink -}}" type="image/webp" /> - {{- end }} - <img - alt="{{ .Data.name }}" - {{- if fileExists $path }} - {{ with $image }} - {{- $image = (.Content | resources.FromString (print (partial "function-paths.html" "media") "/" $.Data.user "/" (path.Base .))).Fit $dimensions -}} - width="{{ $image.Width }}" - height="{{ $image.Height }}" - src="{{ $image.RelPermalink }}" - {{- end }} - {{ else }} - width="{{ $404image.Width }}" - height="{{ $404image.Height }}" - src="{{ $404image.RelPermalink }}" + <micro-thumbnail> + <figure> + <a title="{{ .Data.name }}" href="{{ "" | absURL }}/{{ .Data.user }}/#"> + <picture> + {{- with $sourceset -}} + <source srcset="{{ $sourceset }}" type="image/webp" /> {{- end -}} - /> - </picture> - </a> - </figure> - </micro-thumbnail> + <img + width="{{ $width }}" + height="{{ $height }}" + src="{{ $source }}" + alt="{{ $alternate }}" + /> + </picture> + </a> + </figure> + </micro-thumbnail> + <micro-header> <h2><b>{{ .Data.name }}</b></h2> <h3><a title="{{ .Data.name }}" href="{{ "" | absURL }}/{{ .Data.user }}/#">@{{ .Data.user }}</a></h3> </micro-header> + + <p>{{ .Data.description | markdownify | plainify | htmlUnescape | truncate 60 "..." }}</p> + <a title="Follow with RSS Reader" href="{{ "" | absURL }}/{{ .Data.user }}/rss.xml"> {{ safeHTML (readFile (print (partial "function-paths.html" "static") "/icons/feather/rss.svg")) }} <span>Follow</span> diff --git a/themes/default/layouts/partials/author-header.html b/themes/default/layouts/partials/author-header.html index 6b2fca0..ddb4724 100644 --- a/themes/default/layouts/partials/author-header.html +++ b/themes/default/layouts/partials/author-header.html @@ -1,30 +1,29 @@ -{{- $file := "/profile/header.jpg" -}} -{{- $path := print "public/" (partial "author-media-path.html" .) $file -}} -{{- $image := resources.Get $path -}} -{{- $404image := resources.Get "data/media/404.png" -}} -{{- $dimensions := "x600" -}} -{{- $author := partial "author-user.html" . }} +{{- $author := partial "function-authors-data.html" . -}} +{{- $header := $author.picture.header -}} +{{- $file := not (urls.Parse $header).Host -}} -{{- with $image -}} - {{- $image = .Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/" (path.Base .)) -}} - <source srcset="{{- ($image.Resize (print $dimensions " webp")).RelPermalink -}}" type="image/webp" /> +{{- if $file -}} + {{- $header = print $author.user "/" $header -}} +{{- end -}} + +{{- $image := partial "function-caches-images.html" + (dict + "Source" $header + "Resize" "x600" + "Target" (print (partial "function-paths.html" "media") "/" $author.user "/") + "Copy" (print (partial "function-paths.html" "media") "/" $author.user "/" (path.Base $header)) + "OptimizedCopy" (print (partial "function-paths.html" "media") "/" $author.user "/" (path.BaseName $header) ".webp") + ) +-}} + +{{- with $image.OptRelPermalink -}} + <source srcset="{{ . }}" type="image/webp" /> {{- end -}} <img - {{ if fileExists $path }} - {{- with $image -}} - {{- $image = (.Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/" (path.Base .))).Resize $dimensions -}} width="{{ $image.Width }}" height="{{ $image.Height }}" src="{{ $image.RelPermalink }}" - {{- else -}} - src="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}{{ $file }}" - {{ end }} - {{- else -}} - width="{{ $404image.Width }}" - height="{{ $404image.Height }}" - src="{{ $404image.RelPermalink }}" - {{- end }} - alt="{{ partial "author-name.html" . }}" + alt="{{ $author.name }}" /> {{- /* This comment removes trailing newlines and white spaces. */ -}} diff --git a/themes/default/layouts/partials/author-picture.html b/themes/default/layouts/partials/author-picture.html index b3b4125..ad878bf 100644 --- a/themes/default/layouts/partials/author-picture.html +++ b/themes/default/layouts/partials/author-picture.html @@ -1,41 +1,43 @@ -{{- $file := "/profile/picture.png" -}} -{{- $path := print "public/" (partial "author-media-path.html" .) $file -}} -{{- $image := resources.Get $path -}} -{{- $404image := resources.Get "data/media/404.png" -}} -{{- $dimensions := "160x160" -}} -{{- $author := partial "author-user.html" . -}} +{{- $author := partial "function-authors-data.html" . -}} +{{- $profile := $author.picture.profile -}} +{{- $file := not (urls.Parse $profile).Host -}} -{{- with .Params.feed -}} -{{- else -}} - {{- with $image -}} - {{- $image = .Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/" (path.Base .)) -}} - <source srcset="{{- ($image.Fit (print $dimensions " webp")).RelPermalink -}}" type="image/webp" /> - {{- end -}} -{{ end }} +{{- if $file -}} + {{- $profile = print $author.user "/" $profile -}} +{{- end -}} + +{{- $image := partial "function-caches-images.html" + (dict + "Source" $profile + "Fit" "160x160" + "Target" (print (partial "function-paths.html" "media") "/" $author.user "/") + "Copy" (print (partial "function-paths.html" "media") "/" $author.user "/" (path.Base $profile)) + "OptimizedCopy" (print (partial "function-paths.html" "media") "/" $author.user "/" (path.BaseName $profile) ".webp") + ) +-}} + +{{- $width := $image.Width -}} +{{- $height := $image.Height -}} +{{- $source := $image.RelPermalink -}} +{{- $alternate := $author.name -}} +{{- $sourceset := $image.OptRelPermalink -}} + +{{- with .Params.feed.image -}} + {{- $width = "64" -}} + {{- $height = "64" -}} + {{- $source = $.Params.feed.image -}} + {{- $alternate = $.Params.feed.name -}} + {{- $sourceset = "" -}} +{{- end -}} + +{{- with $sourceset -}} +<source srcset="{{ $sourceset }}" type="image/webp" /> +{{- end -}} <img - loading="lazy" - {{- with .Params.feed }} - width="64" - height="64" - alt="{{ .name }}" - src="{{ .image }}" - {{ else }} - {{ if fileExists $path }} - {{- with $image -}} - {{- $image = (.Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/" (path.Base .))).Fit $dimensions -}} - width="{{ $image.Width }}" - height="{{ $image.Height }}" - src="{{ $image.RelPermalink }}" - {{ else -}} - src="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}{{ $file }}" - {{ end }} - {{- else -}} - width="{{ $404image.Width }}" - height="{{ $404image.Height }}" - src="{{ $404image.RelPermalink }}" - {{- end }} - alt="{{ partial "author-name.html" . }}" - {{ end -}} + width="{{ $width }}" + height="{{ $height }}" + src="{{ $source }}" + alt="{{ $alternate }}" /> {{- /* This comment removes trailing newlines and white spaces. */ -}} diff --git a/themes/default/layouts/partials/function-authors-data.html b/themes/default/layouts/partials/function-authors-data.html new file mode 100644 index 0000000..c4ccf7a --- /dev/null +++ b/themes/default/layouts/partials/function-authors-data.html @@ -0,0 +1,3 @@ +{{- $data := index .Site.Data ((or .Params.author .Site.Author.default.user) | default "default") -}} + +{{- return $data -}} diff --git a/themes/default/layouts/partials/function-caches-images.html b/themes/default/layouts/partials/function-caches-images.html index d21e72a..df5c17f 100644 --- a/themes/default/layouts/partials/function-caches-images.html +++ b/themes/default/layouts/partials/function-caches-images.html @@ -9,7 +9,8 @@ {{- $type := strings.TrimPrefix "." (path.Ext $copy) -}} {{- $optimized := or .OptimizedCopy (print $directory "/" $basename ".webp") -}} {{- $optimizedType := strings.TrimPrefix "." (path.Ext $optimized) -}} -{{- $cached := and (fileExists (print "public/" $copy)) (fileExists (print "public/" $optimized)) -}} +{{- $isFile := ne (path.Base $copy) "." -}} +{{- $cached := and $isFile (fileExists (print "public/" $copy)) (fileExists (print "public/" $optimized)) -}} {{- $local := print "public/" $source -}} {{- $localized := fileExists $local -}} @@ -28,6 +29,9 @@ {{- if $cached -}} {{- with $image := resources.Get (print "public/" $copy) -}} {{- $image = .Content | resources.FromString (print $target (path.Base .)) -}} + {{- with $fit -}} {{- $image = $image.Fit (print $fit " " $type) -}} {{- end -}} + {{- with $resize -}} {{- $image = $image.Resize (print $resize " " $type) -}} {{- end -}} + {{- $image = $image | resources.Copy $copy -}} {{- $data = (dict "Width" $image.Width @@ -36,6 +40,16 @@ "RelPermalink" $image.RelPermalink ) -}} + {{- $image = .Content | resources.FromString (print $target (path.Base .)) -}} + {{- with $fit -}} {{- $image = $image.Fit (print $fit " " $optimizedType) -}} {{- end -}} + {{- with $resize -}} {{- $image = $image.Resize (print $resize " " $optimizedType) -}} {{- end -}} + {{- $image = $image | resources.Copy $optimized -}} + {{- + $data = merge $data (dict + "OptPermalink" $image.Permalink + "OptRelPermalink" $image.RelPermalink + ) + -}} {{- end -}} {{- else -}} {{- with $image := resources.GetRemote $source -}} @@ -46,7 +60,8 @@ {{- $type := strings.TrimPrefix "." (path.Ext $local) -}} {{- with $image := resources.Get $local -}} {{- $image = .Content | resources.FromString (print $target (path.Base .)) -}} - {{- $image = $image.Fit (print $fit " " $type) -}} + {{- with $fit -}} {{- $image = $image.Fit (print $fit " " $type) -}} {{- end -}} + {{- with $resize -}} {{- $image = $image.Resize (print $resize " " $type) -}} {{- end -}} {{- $image = $image | resources.Copy $copy -}} {{- $data = (dict @@ -57,7 +72,8 @@ ) -}} {{- $image = .Content | resources.FromString (print $target (path.Base .)) -}} - {{- $image = $image.Fit (print $fit " " $optimizedType) -}} + {{- with $fit -}} {{- $image = $image.Fit (print $fit " " $optimizedType) -}} {{- end -}} + {{- with $resize -}} {{- $image = $image.Resize (print $resize " " $optimizedType) -}} {{- end -}} {{- $image = $image | resources.Copy $optimized -}} {{- $data = merge $data (dict @@ -69,7 +85,8 @@ {{- end -}} {{- else -}} {{- $image = .Content | resources.FromString (print $target (path.Base .)) -}} - {{- $image = $image.Fit (print $fit " " $type) -}} + {{- with $fit -}} {{- $image = $image.Fit (print $fit " " $type) -}} {{- end -}} + {{- with $resize -}} {{- $image = $image.Resize (print $resize " " $type) -}} {{- end -}} {{- $image = $image | resources.Copy $copy -}} {{- $data = (dict @@ -80,7 +97,8 @@ ) -}} {{- $image = .Content | resources.FromString (print $target (path.Base .)) -}} - {{- $image = $image.Fit (print $fit " " $optimizedType) -}} + {{- with $fit -}} {{- $image = $image.Fit (print $fit " " $optimizedType) -}} {{- end -}} + {{- with $resize -}} {{- $image = $image.Resize (print $resize " " $optimizedType) -}} {{- end -}} {{- $image = $image | resources.Copy $optimized -}} {{- $data = merge $data (dict diff --git a/themes/default/layouts/partials/gallery-walk.html b/themes/default/layouts/partials/gallery-walk.html index 3572ecf..8a22ccf 100644 --- a/themes/default/layouts/partials/gallery-walk.html +++ b/themes/default/layouts/partials/gallery-walk.html @@ -32,54 +32,23 @@ {{- end -}} {{- end -}} - {{- if fileExists (path.Join $folder "profile") -}} - {{- range readDir (path.Join $folder "profile") -}} - - {{- $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 "profile" .Name) - ) - -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- if $files }} {{- range first 6 $files }} - {{- if not .IsDir }} - {{- with $image := resources.Get .Path -}} - {{- $image = (.Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/gallery-walker_" (path.Base .))).Fit (print $dimensions " webp") }} - <picture> - <source srcset="{{- $image.RelPermalink -}}" type="image/webp" /> - {{- $image = (.Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/gallery-walker_" (path.Base .))).Fit (print $dimensions " png") }} - <img - alt="{{- .Name }}" - title="{{- .Name }}" - width="{{ $image.Width }}" - height="{{ $image.Height }}" - src="{{ $image.RelPermalink }}" - /> - </picture> - {{ end }} - {{- end -}} + {{- with $image := resources.Get .Path -}} + {{- $image = (.Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/gallery-walker_" (path.Base .))).Fit (print $dimensions " webp") }} + <picture> + <source srcset="{{- $image.RelPermalink -}}" type="image/webp" /> + {{- $image = (.Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/gallery-walker_" (path.Base .))).Fit (print $dimensions " png") }} + <img + alt="{{- .Name }}" + title="{{- .Name }}" + width="{{ $image.Width }}" + height="{{ $image.Height }}" + src="{{ $image.RelPermalink }}" + /> + </picture> + {{- end -}} {{- end -}} {{- else -}} |