diff --git a/src/components/AuthorList.astro b/src/components/AuthorList.astro new file mode 100644 index 0000000..fa76035 --- /dev/null +++ b/src/components/AuthorList.astro @@ -0,0 +1,36 @@ +--- +import SlackMention from "./SlackMention.astro"; + +interface Props { + authors: string | string[]; + slackIds?: string[]; +} + +const { authors, slackIds } = Astro.props; + +const authorArray = Array.isArray(authors) ? authors : [authors]; + +function normalizeHandle(handle: string): string { + return handle.trim().replace(/^@+/, ""); +} +--- + +{ + authorArray.map((author, index) => ( + <> + {slackIds && slackIds[index] ? ( + + ) : ( + normalizeHandle(author) + )} + {index < authorArray.length - 1 && ( + + {index === authorArray.length - 2 ? " & " : ", "} + + )} + + )) +} diff --git a/src/content.config.ts b/src/content.config.ts index bbc274e..c90f34b 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -6,7 +6,7 @@ const posts = defineCollection({ schema: z.object({ title: z.string(), date: z.coerce.date(), - author: z.string().optional(), + author: z.union([z.string(), z.array(z.string())]).optional(), category: z.string().optional(), excerpt: z.string().optional(), responseTo: z.union([z.string(), z.array(z.string())]).optional(), @@ -26,7 +26,7 @@ const changelogs = defineCollection({ schema: z.object({ title: z.string(), date: z.coerce.date(), - author: z.string(), + author: z.union([z.string(), z.array(z.string())]), excerpt: z.string().optional(), responseTo: z.union([z.string(), z.array(z.string())]).optional(), followUpTo: z.union([z.string(), z.array(z.string())]).optional() diff --git a/src/content/posts/changelogs/responses-and-followups.mdx b/src/content/posts/changelogs/responses-and-followups.mdx index 5056a9a..baa8695 100644 --- a/src/content/posts/changelogs/responses-and-followups.mdx +++ b/src/content/posts/changelogs/responses-and-followups.mdx @@ -1,7 +1,7 @@ --- title: Responses and Followups date: '2026-04-29' -author: '@eps' +author: ['@eps', '@mat'] followUpTo: - "news/welcome-to-slacker-news" --- diff --git a/src/lib/content.ts b/src/lib/content.ts index dd1d025..7b0c900 100644 --- a/src/lib/content.ts +++ b/src/lib/content.ts @@ -19,8 +19,8 @@ export type Post = { slug: string; url: string; title: string; - author?: string; - authorSlackId?: string; + author?: string | string[]; + authorSlackIds?: string[]; category?: string; date: Date; excerpt: string; @@ -38,8 +38,8 @@ export type Post = { type ChangelogBase = { date: string; - author: string; - slackId?: string; + author: string | string[]; + slackIds?: string[]; }; export type ShortChangelogEntry = ChangelogBase & { @@ -100,6 +100,18 @@ function getAuthorSlackId(author: string | undefined): string | undefined { return matchingAcknowledgement?.slackId; } +function getAuthorSlackIds(authors: string | string[] | undefined): string[] { + if (!authors) { + return []; + } + + const authorArray = Array.isArray(authors) ? authors : [authors]; + + return authorArray + .map((author) => getAuthorSlackId(author)) + .filter((id): id is string => Boolean(id)); +} + function replaceSlackMentionComponents(input: string): string { return input.replace(//g, (_match, name) => `@${name}`); } @@ -232,7 +244,7 @@ export async function getPosts(): Promise { url: `/${entry.id}/`, title: entry.data.title, author: entry.data.author, - authorSlackId: getAuthorSlackId(entry.data.author), + authorSlackIds: getAuthorSlackIds(entry.data.author), category, date: entry.data.date, excerpt: toExcerpt({ body: entry.body!, data: entry.data }), @@ -280,7 +292,7 @@ export async function getChangelogEntries(): Promise { change: entry.change, date: entry.date, author: entry.author, - slackId: getAuthorSlackId(entry.author) + slackIds: getAuthorSlackIds(entry.author) })); const longCollection = await getCollection("changelogs"); @@ -306,7 +318,7 @@ export async function getChangelogEntries(): Promise { title: entry.data.title, date: dateString, author: entry.data.author, - slackId: getAuthorSlackId(entry.data.author), + slackIds: getAuthorSlackIds(entry.data.author), excerpt: toExcerpt({ body: entry.body!, data: entry.data }), paragraphs, leadingImage, diff --git a/src/pages/[...slug].astro b/src/pages/[...slug].astro index 754b45d..3fa633b 100644 --- a/src/pages/[...slug].astro +++ b/src/pages/[...slug].astro @@ -1,6 +1,6 @@ --- import BaseLayout from "../layouts/BaseLayout.astro"; -import SlackMention from "../components/SlackMention.astro"; +import AuthorList from "../components/AuthorList.astro"; import { formatStoryDate, getPosts, getSiteConfig } from "../lib/content"; import { render } from "astro:content"; @@ -79,15 +79,7 @@ const followUpLinks = { post.author && ( ) } diff --git a/src/pages/changelogs.astro b/src/pages/changelogs.astro index 285da08..c3fd798 100644 --- a/src/pages/changelogs.astro +++ b/src/pages/changelogs.astro @@ -1,6 +1,6 @@ --- import BaseLayout from "../layouts/BaseLayout.astro"; -import SlackMention from "../components/SlackMention.astro"; +import AuthorList from "../components/AuthorList.astro"; import { getChangelogEntries, getSiteConfig, truncateWords } from "../lib/content"; const site = await getSiteConfig(); @@ -19,7 +19,7 @@ const changelogEntries = await getChangelogEntries();

{entry.title}

{truncateWords(entry.excerpt, 18)}

- {entry.date} · {entry.slackId ? : entry.author} + {entry.date} ·

); @@ -29,7 +29,7 @@ const changelogEntries = await getChangelogEntries();
{entry.change} - {entry.date} · {entry.slackId ? : entry.author} + {entry.date} ·
); diff --git a/src/pages/changelogs/[slug].astro b/src/pages/changelogs/[slug].astro index ad83944..7e3be8b 100644 --- a/src/pages/changelogs/[slug].astro +++ b/src/pages/changelogs/[slug].astro @@ -1,6 +1,6 @@ --- import BaseLayout from "../../layouts/BaseLayout.astro"; -import SlackMention from "../../components/SlackMention.astro"; +import AuthorList from "../../components/AuthorList.astro"; import { formatStoryDate, getChangelogEntries, getSiteConfig, type LongChangelogEntry } from "../../lib/content"; import { render } from "astro:content"; @@ -44,7 +44,7 @@ const { Content } = await render(changelog.entry); {index < recentChangelog.length - 1 &&
}