Skip to content

Commit fe3b3c0

Browse files
authored
Fix multi-author display: render all authors in meta bar instead of only the first
Agent-Logs-Url: https://github.com/recodehive/recode-website/sessions/ddba3cb9-b942-40eb-bbbe-1e0f96800344
1 parent 876f797 commit fe3b3c0

2 files changed

Lines changed: 62 additions & 39 deletions

File tree

src/theme/BlogPostItem/Header/index.tsx

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,16 @@ export default function BlogPostItemHeaderWrapper(props: Props): JSX.Element {
6262
return <BlogPostItemHeaderOriginal {...props} />;
6363
}
6464

65-
const primaryAuthor = metadata.authors?.[0];
66-
const profile = primaryAuthor?.key ? getAuthorProfile(primaryAuthor.key) : undefined;
67-
68-
const authorAvatar = primaryAuthor?.imageURL || profile?.imageUrl;
69-
const authorName = primaryAuthor?.name || profile?.name;
70-
const githubHandle = primaryAuthor
71-
? getGitHubHandle({ key: primaryAuthor.key, url: primaryAuthor.url })
72-
: undefined;
73-
const githubUrl = primaryAuthor
74-
? getGitHubUrl({ key: primaryAuthor.key, url: primaryAuthor.url, name: primaryAuthor.name })
75-
: undefined;
65+
// Build display data for ALL authors (not just the first one)
66+
const authors = (metadata.authors ?? []).map((author) => {
67+
const profile = author.key ? getAuthorProfile(author.key) : undefined;
68+
return {
69+
avatar: author.imageURL || profile?.imageUrl,
70+
name: author.name || profile?.name,
71+
handle: getGitHubHandle({ key: author.key, url: author.url }),
72+
url: getGitHubUrl({ key: author.key, url: author.url, name: author.name }),
73+
};
74+
});
7675

7776
const roundedReadTime = Math.max(1, Math.ceil(metadata.readingTime || 0));
7877
const readTimeText = `${roundedReadTime} min read`;
@@ -94,35 +93,46 @@ export default function BlogPostItemHeaderWrapper(props: Props): JSX.Element {
9493
{/* Render only the title — Info and Authors are replaced by our compact bar */}
9594
<BlogPostItemHeaderTitle />
9695
<div className={styles.metaSection}>
97-
{/* Compact meta row: avatar · @handle · date · reading time */}
96+
{/* Compact meta row: avatars · @handles · date · reading time */}
9897
<div className={styles.metaRow}>
99-
{(authorAvatar || authorName) && (
100-
<div className={styles.authorPart}>
101-
{authorAvatar ? (
102-
<img
103-
className={styles.avatar}
104-
src={authorAvatar}
105-
alt={authorName ? `${authorName} avatar` : "Author avatar"}
106-
loading="lazy"
107-
/>
108-
) : (
109-
<div className={styles.avatarFallback} aria-hidden="true">
110-
{authorName?.charAt(0).toUpperCase()}
111-
</div>
112-
)}
113-
{githubHandle &&
114-
(githubUrl ? (
115-
<Link
116-
to={githubUrl}
117-
className={styles.handle}
118-
target="_blank"
119-
rel="noopener noreferrer"
120-
>
121-
{githubHandle}
122-
</Link>
123-
) : (
124-
<span className={styles.handle}>{githubHandle}</span>
125-
))}
98+
{authors.length > 0 && (
99+
<div className={styles.authorsPart}>
100+
{authors.map((author, idx) => (
101+
<React.Fragment key={author.handle ?? `${author.name ?? ""}-${idx}`}>
102+
{idx > 0 && (
103+
<span className={styles.authorSep} aria-hidden="true">
104+
&amp;
105+
</span>
106+
)}
107+
<div className={styles.authorPart}>
108+
{author.avatar ? (
109+
<img
110+
className={styles.avatar}
111+
src={author.avatar}
112+
alt={author.name ? `${author.name} avatar` : "Author avatar"}
113+
loading="lazy"
114+
/>
115+
) : (
116+
<div className={styles.avatarFallback} aria-hidden="true">
117+
{author.name?.charAt(0).toUpperCase()}
118+
</div>
119+
)}
120+
{author.handle &&
121+
(author.url ? (
122+
<Link
123+
to={author.url}
124+
className={styles.handle}
125+
target="_blank"
126+
rel="noopener noreferrer"
127+
>
128+
{author.handle}
129+
</Link>
130+
) : (
131+
<span className={styles.handle}>{author.handle}</span>
132+
))}
133+
</div>
134+
</React.Fragment>
135+
))}
126136
</div>
127137
)}
128138

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
color: var(--ifm-color-emphasis-700);
2323
}
2424

25+
.authorsPart {
26+
display: flex;
27+
align-items: center;
28+
flex-wrap: wrap;
29+
gap: 0.45rem;
30+
}
31+
32+
.authorSep {
33+
color: var(--ifm-color-emphasis-500);
34+
font-size: 0.8rem;
35+
font-weight: 500;
36+
}
37+
2538
.authorPart {
2639
display: flex;
2740
align-items: center;

0 commit comments

Comments
 (0)