From 41772d6c8cbfd67b03ab6867e38b5e6f49dfd8e7 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Wed, 30 Sep 2020 16:05:49 +0100 Subject: [PATCH] feat: improvements to author profile cards - Re-refactor code to use Hugo's `GetTerms` function now that Hugo fixed the unordered bug - GetTerms may provide better support for names with unicode or spaces - Make avatar pic linked (in addition to name) Close #1750 --- wowchemy/layouts/partials/page_author.html | 11 ++-- .../layouts/partials/page_author_card.html | 51 +++++++++---------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/wowchemy/layouts/partials/page_author.html b/wowchemy/layouts/partials/page_author.html index 56fbea9e..74fa41c0 100644 --- a/wowchemy/layouts/partials/page_author.html +++ b/wowchemy/layouts/partials/page_author.html @@ -6,14 +6,13 @@ {{/* Display superuser if superuser exists and page authors are not explicitly specified. */}} {{/* Otherwise, display first author if a profile for them exists. */}} -{{ $author_urlized := "" }} {{ if and (not .Params.authors) (.Scratch.Get "superuser_username") }} - {{ $author_urlized = (.Scratch.Get "superuser_username") }} - {{ partial "page_author_card" (dict "username" $author_urlized) }} + {{ $author_page := site.GetPage (printf "/%s/%s" "authors" (.Scratch.Get "superuser_username")) }} + {{ partial "page_author_card" (dict "author_page" $author_page) }} {{ else if .Params.authors }} - {{ range $key, $tmp_username := .Params.authors }} - {{ $author_urlized = urlize $tmp_username }} - {{ partial "page_author_card" (dict "username" $author_urlized) }} + {{ $taxonomy := "authors" }} + {{ range $author_obj := (.GetTerms $taxonomy) }} + {{ partial "page_author_card" (dict "author_page" $author_obj.Page) }} {{ end }} {{ end }} diff --git a/wowchemy/layouts/partials/page_author_card.html b/wowchemy/layouts/partials/page_author_card.html index dffdc5d2..6bc06e9d 100644 --- a/wowchemy/layouts/partials/page_author_card.html +++ b/wowchemy/layouts/partials/page_author_card.html @@ -1,31 +1,30 @@ {{ $page := .page }} -{{ $author_urlized := .username }} +{{ $author_page := .author_page }} {{ $site_type := site.Params.site_type | default "Person" }} -{{ $taxonomy := "authors" }} -{{ $profile_page := site.GetPage (printf "/%s/%s" $taxonomy $author_urlized) }} -{{ with $profile_page }} - {{ if isset .Params "superuser" }}{{/* Check an author profile exists. */}} - {{/* If it's a personal site and primary page author is superuser, link to the homepage rather than their profile page. */}} - {{ $profile_url := .RelPermalink }} - {{ if and (eq $site_type "Person") (eq .Params.superuser true) }} - {{ $profile_url = site.BaseURL }} - {{ end }} - {{ $avatar := (.Resources.ByType "image").GetMatch "*avatar*" }} - {{ $avatar_shape := site.Params.avatar.shape | default "circle" }} -
- {{ if and site.Params.avatar.gravatar .Params.email }} - {{.Title}} - {{ else if $avatar }} - {{ $avatar_image := $avatar.Fill "270x270 Center" }} - {{.Title}} - {{ end }} +{{- $has_profile := not (eq nil $author_page.Params.superuser) -}} -
-
{{.Title}}
- {{ with .Params.role }}
{{. | markdownify | emojify}}
{{end}} - {{ with .Params.bio }}

{{. | markdownify | emojify}}

{{end}} - {{ partial "social_links" . }} -
+{{/* Check an author profile exists. */}} +{{ if $has_profile }} + {{/* If it's a personal site and primary page author is superuser, link to the homepage rather than their profile page. */}} + {{ $profile_url := $author_page.RelPermalink }} + {{ if and (eq $site_type "Person") (eq $author_page.Params.superuser true) }} + {{ $profile_url = site.BaseURL }} + {{ end }} + {{ $avatar := ($author_page.Resources.ByType "image").GetMatch "*avatar*" }} + {{ $avatar_shape := site.Params.avatar.shape | default "circle" }} +
+ {{ if and site.Params.avatar.gravatar $author_page.Params.email }} + {{$author_page.Title}} + {{ else if $avatar }} + {{ $avatar_image := $avatar.Fill "270x270 Center" }} + {{$author_page.Title}} + {{ end }} + +
+
{{$author_page.Title}}
+ {{ with $author_page.Params.role }}
{{. | markdownify | emojify}}
{{end}} + {{ with $author_page.Params.bio }}

{{. | markdownify | emojify}}

{{end}} + {{ partial "social_links" $author_page }}
- {{end}} +
{{end}}{{/* Profile page block */}}