Skip to content

Commit fb33583

Browse files
authored
feat: make author card avatar, name, and @handle link to GitHub profile
Agent-Logs-Url: https://github.com/recodehive/recode-website/sessions/8592d8cd-9b6f-4016-9f86-dee00fff62b5
1 parent 3e3fa3e commit fb33583

2 files changed

Lines changed: 80 additions & 6 deletions

File tree

src/theme/BlogPostItem/Footer/index.tsx

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ export default function BlogPostItemFooterWrapper(props: Props): JSX.Element {
8989
month: "short",
9090
day: "numeric",
9191
}).format(new Date(metadata.date));
92-
const metaItems = [authorHandle, blogDate, readTimeText]
93-
.filter(Boolean)
94-
.join(META_SEPARATOR);
92+
const metaDateAndTime = [blogDate, readTimeText].filter(Boolean).join(META_SEPARATOR);
9593

9694
const showAuthorCard = Boolean(isBlogPostPage && primaryAuthor && authorName);
9795

@@ -111,7 +109,28 @@ export default function BlogPostItemFooterWrapper(props: Props): JSX.Element {
111109
<section ref={authorCardRef} className={styles.authorCard} aria-label="Post author details">
112110
<div className={styles.authorBody}>
113111
<div className={styles.authorAvatarWrapper}>
114-
{authorAvatar ? (
112+
{githubUrl ? (
113+
<Link
114+
to={githubUrl}
115+
className={styles.authorAvatarLink}
116+
target="_blank"
117+
rel="noopener noreferrer"
118+
aria-label={`${authorName} on GitHub`}
119+
>
120+
{authorAvatar ? (
121+
<img
122+
className={styles.authorAvatar}
123+
src={authorAvatar}
124+
alt={`${authorName} profile picture`}
125+
loading="lazy"
126+
/>
127+
) : (
128+
<div className={styles.authorAvatarFallback} aria-hidden="true">
129+
{authorName?.charAt(0).toUpperCase()}
130+
</div>
131+
)}
132+
</Link>
133+
) : authorAvatar ? (
115134
<img
116135
className={styles.authorAvatar}
117136
src={authorAvatar}
@@ -137,10 +156,40 @@ export default function BlogPostItemFooterWrapper(props: Props): JSX.Element {
137156
</div>
138157
<div className={styles.authorIdentity}>
139158
<div className={styles.authorNameRow}>
140-
<p className={styles.authorName}>{authorName}</p>
159+
{githubUrl ? (
160+
<Link
161+
to={githubUrl}
162+
className={styles.authorName}
163+
target="_blank"
164+
rel="noopener noreferrer"
165+
>
166+
{authorName}
167+
</Link>
168+
) : (
169+
<p className={styles.authorName}>{authorName}</p>
170+
)}
141171
<span className={styles.authorBadge}>Author</span>
142172
</div>
143-
{metaItems ? <p className={styles.authorMeta}>{metaItems}</p> : null}
173+
{(authorHandle || metaDateAndTime) ? (
174+
<p className={styles.authorMeta}>
175+
{authorHandle && (
176+
githubUrl ? (
177+
<Link
178+
to={githubUrl}
179+
className={styles.authorHandleLink}
180+
target="_blank"
181+
rel="noopener noreferrer"
182+
>
183+
{authorHandle}
184+
</Link>
185+
) : (
186+
authorHandle
187+
)
188+
)}
189+
{authorHandle && metaDateAndTime ? META_SEPARATOR : null}
190+
{metaDateAndTime}
191+
</p>
192+
) : null}
144193
{authorSummary ? (
145194
<p className={styles.authorSummary}>{authorSummary}</p>
146195
) : null}

src/theme/BlogPostItem/Footer/styles.module.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
justify-content: center;
3535
}
3636

37+
.authorAvatarLink {
38+
display: block;
39+
line-height: 0;
40+
border-radius: 50%;
41+
}
42+
43+
.authorAvatarLink:hover {
44+
opacity: 0.85;
45+
}
46+
3747
.authorAvatar,
3848
.authorAvatarFallback {
3949
width: 64px;
@@ -64,6 +74,21 @@
6474
font-size: 1.75rem;
6575
font-weight: 800;
6676
line-height: 1.2;
77+
color: var(--ifm-font-color-base);
78+
text-decoration: none;
79+
}
80+
81+
.authorName:hover {
82+
text-decoration: underline;
83+
}
84+
85+
.authorHandleLink {
86+
color: inherit;
87+
text-decoration: none;
88+
}
89+
90+
.authorHandleLink:hover {
91+
text-decoration: underline;
6792
}
6893

6994
.authorNameRow {

0 commit comments

Comments
 (0)