Skip to content

Commit 578c956

Browse files
committed
feat: show multiple authors in single line in docs page (#44)
1 parent d42d829 commit 578c956

File tree

2 files changed

+85
-10
lines changed

2 files changed

+85
-10
lines changed

src/app/docs/[[...slug]]/page.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,7 @@ export default async function Page(props: PageProps<"/docs/[[...slug]]">) {
6767
<DocsDescription className="!mb-2 text-base">{data.description}</DocsDescription>
6868
{data.authors && data.authors.length > 0 && (
6969
<div className="mb-4">
70-
{data.authors.map((author: string) => (
71-
<AuthorCard
72-
key={author}
73-
author={author}
74-
authorURL={`https://github.com/${author}`}
75-
date={data.date}
76-
readTime={readTime}
77-
className="mb-2"
78-
/>
79-
))}
70+
<AuthorCard authors={data.authors} date={data.date} readTime={readTime} />
8071
</div>
8172
)}
8273
<div className="flex flex-row gap-2 items-center border-b pt-1 pb-4">

src/components/blog/AuthorCard.tsx

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface AuthorCardProps {
66
author?: string;
77
authorURL?: string;
88
authorImageURL?: string;
9+
authors?: string[];
910
date?: string;
1011
readTime?: string;
1112
className?: string;
@@ -37,10 +38,93 @@ export function AuthorCard({
3738
author,
3839
authorURL,
3940
authorImageURL,
41+
authors,
4042
date,
4143
readTime,
4244
className,
4345
}: AuthorCardProps) {
46+
// Handle multiple authors case
47+
if (authors && authors.length > 0) {
48+
const formattedDate = date
49+
? new Date(date).toLocaleDateString("en-US", {
50+
month: "short",
51+
day: "numeric",
52+
year: "numeric",
53+
})
54+
: null;
55+
56+
return (
57+
<div
58+
className={cn("flex flex-wrap items-center gap-2 text-sm text-muted-foreground", className)}
59+
>
60+
{authors.flatMap((authorName, index) => {
61+
const githubUrl = `https://github.com/${encodeURIComponent(authorName)}`;
62+
const avatarUrl = !authorName.includes(" ")
63+
? `https://github.com/${encodeURIComponent(authorName)}.png`
64+
: null;
65+
66+
const elements = [];
67+
68+
if (avatarUrl) {
69+
elements.push(
70+
<div className="relative shrink-0" key={`${authorName}-${index}-avatar`}>
71+
<Link
72+
href={githubUrl}
73+
target="_blank"
74+
rel="noopener noreferrer"
75+
className="block leading-none"
76+
>
77+
<Avatar className="h-6 w-6 border border-border/50">
78+
<AvatarImage src={avatarUrl} alt={authorName} className="object-cover" />
79+
<AvatarFallback>{authorName.charAt(0).toUpperCase()}</AvatarFallback>
80+
</Avatar>
81+
</Link>
82+
</div>,
83+
);
84+
}
85+
86+
elements.push(
87+
<div className="font-semibold text-foreground" key={`${authorName}-${index}-name`}>
88+
<Link
89+
href={githubUrl}
90+
target="_blank"
91+
rel="noopener noreferrer"
92+
className="hover:underline"
93+
>
94+
{authorName}
95+
</Link>
96+
</div>,
97+
);
98+
99+
if (index < authors.length - 1) {
100+
elements.push(
101+
<span aria-hidden="true" key={`${authorName}-${index}-comma`}>
102+
,
103+
</span>,
104+
);
105+
}
106+
107+
return elements;
108+
})}
109+
110+
{readTime && (
111+
<>
112+
<span aria-hidden="true">·</span>
113+
<span>{readTime} read</span>
114+
</>
115+
)}
116+
117+
{formattedDate && (
118+
<>
119+
<span aria-hidden="true">·</span>
120+
<time dateTime={date}>{formattedDate}</time>
121+
</>
122+
)}
123+
</div>
124+
);
125+
}
126+
127+
// Handle single author case (backward compatibility)
44128
if (!author && !date) return null;
45129

46130
const githubUrl = sanitizeAuthorUrl(authorURL);

0 commit comments

Comments
 (0)