From d27b1096ac6f3f9d5880ecbd97097bfceecefa13 Mon Sep 17 00:00:00 2001 From: tdro Date: Mon, 26 Dec 2022 17:01:51 -0500 Subject: themes/default/layouts/partials: Mix down image metadata and expose author.json Relegate to section and reduce the rate of multiplicative image transformations --- assets/css/default.css | 3 +- themes/default/layouts/_default/rss.xml | 43 +++++++--------------- themes/default/layouts/_default/section.html | 16 +++++--- themes/default/layouts/partials/author-card.html | 40 ++++++++------------ .../default/layouts/partials/author-picture.html | 43 +++++++++++----------- .../layouts/partials/author-section-picture.html | 37 +++++++++++++++++++ 6 files changed, 101 insertions(+), 81 deletions(-) create mode 100644 themes/default/layouts/partials/author-section-picture.html diff --git a/assets/css/default.css b/assets/css/default.css index a33ac62..a6e7c43 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -1510,7 +1510,8 @@ web-ring header { font-weight: 700; } -web-ring time { +web-ring time, +following-list time { font-variant: small-caps; color: #444; color: var(--fade); diff --git a/themes/default/layouts/_default/rss.xml b/themes/default/layouts/_default/rss.xml index 2925201..9206978 100644 --- a/themes/default/layouts/_default/rss.xml +++ b/themes/default/layouts/_default/rss.xml @@ -24,23 +24,14 @@ {{- $description = print .Site.Title " Tags: #" .Title -}} {{- end -}} -{{- $profile := $author.picture.profile -}} -{{- $file := not (urls.Parse $profile).Host -}} +{{- $image := print "/" (partial "function-paths.html" "media") + "/" $author.user "/" $author.user "-profile" (path.Ext $author.picture.profile) +-}} -{{- if $file -}} - {{- $profile = print $author.user "/" $profile -}} +{{- if not (fileExists (print "public/" $image)) -}} + {{- $image = "/data/media/404.png" -}} {{- 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)) - "AlternateCopy" (print (partial "function-paths.html" "media") "/" $author.user "/" (path.BaseName $profile) ".webp") - ) --}} - {{- $atomSelf := "" -}} {{- $atomPrevious := "" -}} {{- $atomNext := "" -}} @@ -76,7 +67,7 @@ {{ $lastBuildDate }} {{ $title }} - {{ $image.Permalink }} + {{ .Site.BaseURL }}{{ $image }} {{ .Permalink }} @@ -87,24 +78,16 @@ {{ range first $limit $filteredPages -}} {{- $author = partial "function-authors-data.html" . -}} - {{- $profile = $author.picture.profile -}} - {{- $file = not (urls.Parse $profile).Host -}} - {{- 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)) - "AlternateCopy" (print (partial "function-paths.html" "media") "/" $author.user "/" (path.BaseName $profile) ".webp") - ) + {{- $image = print "/" (partial "function-paths.html" "media") + "/" $author.user "/" $author.user "-profile" (path.Ext $author.picture.profile) -}} - {{- $atomAuthorUri := $image.Permalink -}} + {{- if not (fileExists (print "public/" $image)) -}} + {{- $image = "/data/media/404.png" -}} + {{- end -}} + + {{- $atomAuthorUri := print .Site.BaseURL $image -}} {{- $atomAuthorName := or .Params.Feed.name $author.name -}} {{- if .Params.Feed.favicon -}} diff --git a/themes/default/layouts/_default/section.html b/themes/default/layouts/_default/section.html index ccb2746..97436fa 100644 --- a/themes/default/layouts/_default/section.html +++ b/themes/default/layouts/_default/section.html @@ -17,7 +17,11 @@ {{ define "middle" }} - {{- $messages := print (lang.FormatNumberCustom 0 .Paginator.TotalNumberOfElements) " " "Messages" -}} + {{- $messages := print + (lang.FormatNumberCustom 0 .Paginator.TotalNumberOfElements) + " " + "Messages" + -}} {{ partial "navigator-middle.html" (dict @@ -31,14 +35,16 @@ ) }} + {{ partial "author-section-picture.html" . }} + {{ partial "profile.html" . }} {{ range .Paginator.Pages }} {{ .Render "summary" }} {{ else }} - + {{ end }} {{ partial "pagination.html" . }} @@ -46,5 +52,5 @@ {{ end }} {{ define "right" }} - {{- partial "navigator-right.html" . -}} + {{- partial "navigator-right.html" . -}} {{ end }} diff --git a/themes/default/layouts/partials/author-card.html b/themes/default/layouts/partials/author-card.html index 3da9ab2..2897e62 100644 --- a/themes/default/layouts/partials/author-card.html +++ b/themes/default/layouts/partials/author-card.html @@ -1,5 +1,4 @@ -{{- $profile := .Data.picture.profile -}} -{{- $file := not (urls.Parse $profile).Host -}} +{{- $metadata := print "public/" .Data.user "/author.json" -}} {{- $host := (urls.Parse ("" | absURL)).Host -}} @@ -7,31 +6,24 @@ {{- $host = "localhost" -}} {{- end -}} -{{- if $file -}} - {{- $profile = print .Data.user "/" $profile -}} -{{- end -}} +{{- $alternate := .Data.name -}} +{{- $width := "" -}} +{{- $height := "" -}} +{{- $source := "" -}} +{{- $sourceset := "" -}} -{{- $image := partial "function-caches-images.html" - (dict - "Source" $profile - "Fit" "160x160" - "Target" (print (partial "function-paths.html" "media") "/" .Data.user "/") - "Copy" (print (partial "function-paths.html" "media") "/" .Data.user "/" (path.Base $profile)) - "AlternateCopy" (print (partial "function-paths.html" "media") "/" .Data.user "/" (path.BaseName $profile) ".webp") - ) --}} +{{- $source = print "/" (partial "function-paths.html" "media") "/" .Data.user "/" .Data.user "-profile" (path.Ext .Data.picture.profile) -}} +{{- $sourceset = print "/" (partial "function-paths.html" "media") "/" .Data.user "/" .Data.user "-profile.webp" -}} -{{- $width := $image.Width -}} -{{- $height := $image.Height -}} -{{- $source := $image.RelPermalink -}} -{{- $alternate := .Data.name -}} -{{- $sourceset := $image.AltRelPermalink -}} +{{- with $metadata := resources.Get $metadata -}} + {{- $metadata = $metadata.Content | transform.Unmarshal -}} + {{- $width = $metadata.picture.profileWidth -}} + {{- $height = $metadata.picture.profileHeight -}} +{{- end -}} -{{- with .Params.feed.favicon -}} - {{- $width = "64" -}} - {{- $height = "64" -}} - {{- $source = $.Params.feed.favicon -}} - {{- $alternate = $.Params.feed.name -}} +{{- if not (fileExists (print "public/" $source)) -}} + {{- $source = "/data/media/404.png" -}} + {{- $sourceset = "" -}} {{- end -}} diff --git a/themes/default/layouts/partials/author-picture.html b/themes/default/layouts/partials/author-picture.html index d2c3c6f..05d5cf1 100644 --- a/themes/default/layouts/partials/author-picture.html +++ b/themes/default/layouts/partials/author-picture.html @@ -1,32 +1,33 @@ {{- $author := partial "function-authors-data.html" . -}} -{{- $profile := $author.picture.profile -}} -{{- $file := not (urls.Parse $profile).Host -}} +{{- $metadata := print "public/" $author.user "/author.json" -}} -{{- 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)) - "AlternateCopy" (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.AltRelPermalink -}} +{{- $width := "" -}} +{{- $height := "" -}} +{{- $source := "" -}} +{{- $sourceset := "" -}} {{- with .Params.feed.favicon -}} + {{- $alternate = $.Params.feed.name -}} {{- $width = "64" -}} {{- $height = "64" -}} {{- $source = $.Params.feed.favicon -}} - {{- $alternate = $.Params.feed.name -}} + {{- $sourceset = "" -}} +{{- else -}} + {{- $source = print "/" (partial "function-paths.html" "media") "/" $author.user "/" $author.user "-profile" (path.Ext $author.picture.profile) -}} + {{- $sourceset = print "/" (partial "function-paths.html" "media") "/" $author.user "/" $author.user "-profile.webp" -}} + {{- with $metadata := resources.Get $metadata -}} + {{- $metadata = $metadata.Content | transform.Unmarshal -}} + {{- $width = $metadata.picture.profileWidth -}} + {{- $height = $metadata.picture.profileHeight -}} + {{- else -}} + {{- $source = "/data/media/404.png" -}} + {{- $sourceset = "" -}} + {{- end -}} +{{- end -}} + +{{- if not (path.Ext $author.picture.profile) -}} + {{- $source = "/data/media/404.png" -}} {{- $sourceset = "" -}} {{- end -}} diff --git a/themes/default/layouts/partials/author-section-picture.html b/themes/default/layouts/partials/author-section-picture.html new file mode 100644 index 0000000..5b718d4 --- /dev/null +++ b/themes/default/layouts/partials/author-section-picture.html @@ -0,0 +1,37 @@ +{{- $author := partial "function-authors-data.html" . -}} +{{- $profile := $author.picture.profile -}} +{{- $file := not (urls.Parse $profile).Host -}} + +{{- 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 "/" $author.user "-profile" (path.Ext $profile)) + "AlternateCopy" (print (partial "function-paths.html" "media") "/" $author.user "/" $author.user "-profile.webp") + ) +-}} + +{{- $width := $image.Width -}} +{{- $height := $image.Height -}} +{{- $source := $image.RelPermalink -}} +{{- $alternate := $author.name -}} +{{- $sourceset := $image.AltRelPermalink -}} + +{{- $metadata := (dict + "picture" (dict + "profileWidth" $width + "profileHeight" $height + "profileSource" $source + "profileAlternate" $alternate + "profileSourceSet" $sourceset + ) + ) +-}} + +{{- $authorMetadata := merge $author $metadata | jsonify | resources.FromString (print .Section "/author.json") -}} +{{- $writeToFile := $authorMetadata.Permalink -}} -- cgit v1.2.3