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
This commit is contained in:
George Cushen 2020-09-30 16:05:49 +01:00
commit 41772d6c8c
2 changed files with 30 additions and 32 deletions

View file

@ -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 }}

View file

@ -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" }}
<div class="media author-card content-widget-hr">
{{ if and site.Params.avatar.gravatar .Params.email }}
<img class="avatar mr-3 {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="https://s.gravatar.com/avatar/{{ md5 .Params.email }}?s=200')" alt="{{.Title}}">
{{ else if $avatar }}
{{ $avatar_image := $avatar.Fill "270x270 Center" }}
<img class="avatar mr-3 {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="{{ $avatar_image.RelPermalink }}" alt="{{.Title}}">
{{ end }}
{{- $has_profile := not (eq nil $author_page.Params.superuser) -}}
<div class="media-body">
<h5 class="card-title"><a href="{{$profile_url}}">{{.Title}}</a></h5>
{{ with .Params.role }}<h6 class="card-subtitle">{{. | markdownify | emojify}}</h6>{{end}}
{{ with .Params.bio }}<p class="card-text">{{. | markdownify | emojify}}</p>{{end}}
{{ partial "social_links" . }}
</div>
{{/* 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" }}
<div class="media author-card content-widget-hr">
{{ if and site.Params.avatar.gravatar $author_page.Params.email }}
<a href="{{$profile_url}}"><img class="avatar mr-3 {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="https://s.gravatar.com/avatar/{{ md5 $author_page.Params.email }}?s=200')" alt="{{$author_page.Title}}"></a>
{{ else if $avatar }}
{{ $avatar_image := $avatar.Fill "270x270 Center" }}
<a href="{{$profile_url}}"><img class="avatar mr-3 {{if eq $avatar_shape "square"}}avatar-square{{else}}avatar-circle{{end}}" src="{{ $avatar_image.RelPermalink }}" alt="{{$author_page.Title}}"></a>
{{ end }}
<div class="media-body">
<h5 class="card-title"><a href="{{$profile_url}}">{{$author_page.Title}}</a></h5>
{{ with $author_page.Params.role }}<h6 class="card-subtitle">{{. | markdownify | emojify}}</h6>{{end}}
{{ with $author_page.Params.bio }}<p class="card-text">{{. | markdownify | emojify}}</p>{{end}}
{{ partial "social_links" $author_page }}
</div>
{{end}}
</div>
{{end}}{{/* Profile page block */}}