Skip to content

Commit e9f3d8a

Browse files
committed
feat(ui): display author avatar in post metadata
Requested in #83 Signed-off-by: Khusika Dhamar Gusti <[email protected]>
1 parent 01245f8 commit e9f3d8a

File tree

5 files changed

+87
-8
lines changed

5 files changed

+87
-8
lines changed

archetypes/default.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ lastmod: {{ .Date }}
66
draft: true
77
author: ""
88
authorLink: ""
9+
# Author's avatar (choose one, gravatarEmail has priority)
10+
gravatarEmail: ""
11+
# avatarURL: ""
912
description: ""
1013

1114
tags: []

assets/css/_page/_home.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@
164164
}
165165
}
166166

167+
.post-author {
168+
vertical-align: middle;
169+
.author {
170+
display: inline-flex;
171+
align-items: center;
172+
}
173+
.avatar {
174+
width: 1.5rem;
175+
height: 1.5rem;
176+
border-radius: 50%;
177+
margin-right: .5rem;
178+
}
179+
}
180+
167181
p {
168182
margin: .5rem 0;
169183
}

assets/css/_page/_single.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@
5050
}
5151
}
5252

53+
.post-author {
54+
vertical-align: middle;
55+
.author {
56+
display: inline-flex;
57+
align-items: center;
58+
}
59+
.avatar {
60+
width: 1.5rem;
61+
height: 1.5rem;
62+
border-radius: 50%;
63+
margin-right: .5rem;
64+
}
65+
}
66+
5367
.featured-image {
5468
margin: 1rem 0 0;
5569

layouts/posts/single.html

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,35 @@ <h2 class="single-subtitle">{{ . }}</h2>
4343
{{- /* Meta */ -}}
4444
<div class="post-meta">
4545
<div class="post-meta-line">
46-
{{- $author := $params.author | default .Site.Author.name | default (T "author") -}}
47-
{{- $authorLink := $params.authorlink | default .Site.Author.link | default .Site.Home.RelPermalink -}}
46+
{{- $author := .Params.author | default .Site.Author.name | default (T "author") -}}
47+
{{- $authorLink := .Params.authorlink | default .Site.Author.link | default .Site.Home.RelPermalink -}}
4848
<span class="post-author">
49-
{{- $options := dict "Class" "author" "Destination" $authorLink "Title" "Author" "Rel" "author" "Icon" (dict "Class" "fa-solid fa-user-circle fa-fw") "Content" $author -}}
50-
{{- partial "plugin/link.html" $options -}}
49+
{{- $avatar := "" -}}
50+
{{- with .Params.gravatarEmail -}}
51+
{{- $avatar = md5 . | printf "https://www.gravatar.com/avatar/%v?s=240&d=mp" -}}
52+
{{- else -}}
53+
{{- with .Params.avatarURL -}}
54+
{{- $avatar = . | relURL -}}
55+
{{- else -}}
56+
{{- with .Site.Params.home.profile.gravatarEmail -}}
57+
{{- $avatar = md5 . | printf "https://www.gravatar.com/avatar/%v?s=240&d=mp" -}}
58+
{{- else -}}
59+
{{- with .Site.Params.home.profile.avatarURL -}}
60+
{{- $avatar = . | relURL -}}
61+
{{- end -}}
62+
{{- end -}}
63+
{{- end -}}
64+
{{- end -}}
65+
66+
{{- if $avatar -}}
67+
<a href="{{ $authorLink }}" title="Author" rel="author" class="author">
68+
{{- dict "Src" $avatar "Class" "avatar" | partial "plugin/image.html" -}}
69+
<span class="post-author-name">{{ $author }}</span>
70+
</a>
71+
{{- else -}}
72+
{{- $options := dict "Class" "author" "Destination" $authorLink "Title" "Author" "Rel" "author" "Icon" (dict "Class" "fa-solid fa-user-circle fa-fw") "Content" $author -}}
73+
{{- partial "plugin/link.html" $options -}}
74+
{{- end -}}
5175
</span>
5276

5377
{{- $categories := slice -}}

layouts/summary.html

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,35 @@ <h2 class="single-title" itemprop="name headline">
2626

2727
{{- /* Meta */ -}}
2828
<div class="post-meta">
29-
{{- $author := $params.author | default .Site.Author.name | default (T "author") -}}
30-
{{- $authorLink := $params.authorlink | default .Site.Author.link | default .Site.Home.RelPermalink -}}
29+
{{- $author := .Params.author | default .Site.Author.name | default (T "author") -}}
30+
{{- $authorLink := .Params.authorlink | default .Site.Author.link | default .Site.Home.RelPermalink -}}
3131
<span class="post-author">
32-
{{- $options := dict "Class" "author" "Destination" $authorLink "Title" "Author" "Rel" "author" "Icon" (dict "Class" "fa-solid fa-user-circle fa-fw") "Content" $author -}}
33-
{{- partial "plugin/link.html" $options -}}
32+
{{- $avatar := "" -}}
33+
{{- with .Params.gravatarEmail -}}
34+
{{- $avatar = md5 . | printf "https://www.gravatar.com/avatar/%v?s=240&d=mp" -}}
35+
{{- else -}}
36+
{{- with .Params.avatarURL -}}
37+
{{- $avatar = . | relURL -}}
38+
{{- else -}}
39+
{{- with .Site.Params.home.profile.gravatarEmail -}}
40+
{{- $avatar = md5 . | printf "https://www.gravatar.com/avatar/%v?s=240&d=mp" -}}
41+
{{- else -}}
42+
{{- with .Site.Params.home.profile.avatarURL -}}
43+
{{- $avatar = . | relURL -}}
44+
{{- end -}}
45+
{{- end -}}
46+
{{- end -}}
47+
{{- end -}}
48+
49+
{{- if $avatar -}}
50+
<a href="{{ $authorLink }}" title="Author" rel="author" class="author">
51+
{{- dict "Src" $avatar "Class" "avatar" | partial "plugin/image.html" -}}
52+
<span class="post-author-name">{{ $author }}</span>
53+
</a>
54+
{{- else -}}
55+
{{- $options := dict "Class" "author" "Destination" $authorLink "Title" "Author" "Rel" "author" "Icon" (dict "Class" "fa-solid fa-user-circle fa-fw") "Content" $author -}}
56+
{{- partial "plugin/link.html" $options -}}
57+
{{- end -}}
3458
</span>
3559

3660
{{- with .Site.Params.dateFormat | default "2006-01-02" | .PublishDate.Format -}}

0 commit comments

Comments
 (0)