From 5c08d7666c3b4f75207822344edb7f54e1c4b0cb Mon Sep 17 00:00:00 2001 From: tdro Date: Sun, 28 Aug 2022 00:08:03 -0400 Subject: themes/default/layouts/partials/function-caches-images: Merge alternate copy properties Compensate for fit and resize. Set images from user profile configuration. --- content/canory/media/header.jpg | Bin 0 -> 247768 bytes content/canory/media/picture.png | Bin 0 -> 182233 bytes content/canory/media/profile/header.jpg | Bin 247768 -> 0 bytes content/canory/media/profile/picture.png | Bin 182233 -> 0 bytes content/default/media/header.jpg | Bin 0 -> 542296 bytes content/default/media/picture.png | Bin 0 -> 31774 bytes content/default/media/profile/header.jpg | Bin 542296 -> 0 bytes content/default/media/profile/picture.png | Bin 31774 -> 0 bytes data/canory.yaml | 4 +- data/default.yaml | 4 +- themes/default/layouts/partials/author-card.html | 74 ++++++++++++--------- themes/default/layouts/partials/author-header.html | 41 ++++++------ .../default/layouts/partials/author-picture.html | 74 +++++++++++---------- .../layouts/partials/function-authors-data.html | 3 + .../layouts/partials/function-caches-images.html | 28 ++++++-- themes/default/layouts/partials/gallery-walk.html | 59 ++++------------ 16 files changed, 146 insertions(+), 141 deletions(-) create mode 100644 content/canory/media/header.jpg create mode 100644 content/canory/media/picture.png delete mode 100644 content/canory/media/profile/header.jpg delete mode 100644 content/canory/media/profile/picture.png create mode 100644 content/default/media/header.jpg create mode 100644 content/default/media/picture.png delete mode 100644 content/default/media/profile/header.jpg delete mode 100644 content/default/media/profile/picture.png create mode 100644 themes/default/layouts/partials/function-authors-data.html diff --git a/content/canory/media/header.jpg b/content/canory/media/header.jpg new file mode 100644 index 0000000..846ed6a Binary files /dev/null and b/content/canory/media/header.jpg differ diff --git a/content/canory/media/picture.png b/content/canory/media/picture.png new file mode 100644 index 0000000..20bf810 Binary files /dev/null and b/content/canory/media/picture.png differ diff --git a/content/canory/media/profile/header.jpg b/content/canory/media/profile/header.jpg deleted file mode 100644 index 846ed6a..0000000 Binary files a/content/canory/media/profile/header.jpg and /dev/null differ diff --git a/content/canory/media/profile/picture.png b/content/canory/media/profile/picture.png deleted file mode 100644 index 20bf810..0000000 Binary files a/content/canory/media/profile/picture.png and /dev/null differ diff --git a/content/default/media/header.jpg b/content/default/media/header.jpg new file mode 100644 index 0000000..e2578d5 Binary files /dev/null and b/content/default/media/header.jpg differ diff --git a/content/default/media/picture.png b/content/default/media/picture.png new file mode 100644 index 0000000..6e039c0 Binary files /dev/null and b/content/default/media/picture.png differ diff --git a/content/default/media/profile/header.jpg b/content/default/media/profile/header.jpg deleted file mode 100644 index e2578d5..0000000 Binary files a/content/default/media/profile/header.jpg and /dev/null differ diff --git a/content/default/media/profile/picture.png b/content/default/media/profile/picture.png deleted file mode 100644 index 6e039c0..0000000 Binary files a/content/default/media/profile/picture.png and /dev/null differ diff --git a/data/canory.yaml b/data/canory.yaml index 5c47ca7..e2ee509 100644 --- a/data/canory.yaml +++ b/data/canory.yaml @@ -9,8 +9,8 @@ domain: url: https://example.com epoch: Arrived on the second fortnight of April, `2022` picture: - header: - profile: + header: media/header.jpg + profile: media/picture.png description: > Descended from an inner star system of the Sunflower galaxy. Not an owl. Theme Canory --- a micro blog theme for [Hugo](https://gohugo.io/), one of many diff --git a/data/default.yaml b/data/default.yaml index 0c45725..ef4c414 100644 --- a/data/default.yaml +++ b/data/default.yaml @@ -8,8 +8,8 @@ domain: host: default.example url: https://example.com picture: - header: - profile: + header: media/header.jpg + profile: media/picture.png epoch: Appeared sometime around April, `2022` description: > Dignissimos quis animi velit. Not a bot. If you believe everything you read on 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 -}} - -
- - - {{- with $image }} - {{- $image = .Content | resources.FromString (print (partial "function-paths.html" "media") "/" $.Data.user "/" (path.Base .)) }} - - {{- end }} - {{ .Data.name }} +
+ + + {{- with $sourceset -}} + {{- end -}} - /> - - -
- + {{ $alternate }} + + +
+
+

{{ .Data.name }}

@{{ .Data.user }}

+ +

{{ .Data.description | markdownify | plainify | htmlUnescape | truncate 60 "..." }}

+ {{ safeHTML (readFile (print (partial "function-paths.html" "static") "/icons/feather/rss.svg")) }} Follow 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 .)) -}} - +{{- 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 -}} + {{- end -}} {{ partial {{- /* 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 .)) -}} - - {{- 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 -}} + +{{- end -}} {{ .name }} {{- /* 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") }} - - - {{- $image = (.Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/gallery-walker_" (path.Base .))).Fit (print $dimensions " png") }} - {{- .Name }} - - {{ 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") }} + + + {{- $image = (.Content | resources.FromString (print (partial "function-paths.html" "media") "/" $author "/gallery-walker_" (path.Base .))).Fit (print $dimensions " png") }} + {{- .Name }} + + {{- end -}} {{- end -}} {{- else -}} -- cgit v1.2.3