|
28 | 28 |
|
29 | 29 | export let title: string; |
30 | 30 | export let description: string; |
31 | | - export let author: string; |
| 31 | + export let author: string | string[]; |
32 | 32 | export let date: string; |
33 | 33 | export let timeToRead: string; |
34 | 34 | export let cover: string; |
|
40 | 40 | (post) => !(post.unlisted ?? false) && !(post.draft ?? false) |
41 | 41 | ); |
42 | 42 | const authors = getContext<AuthorData[]>('authors'); |
43 | | - const authorData = authors.find((a) => a.slug === author); |
| 43 | + const authorSlugs = Array.isArray(author) ? author : [author]; |
| 44 | + const authorData = authorSlugs |
| 45 | + .map((slug) => authors.find((a) => a.slug === slug)) |
| 46 | + .filter((a): a is AuthorData => a !== undefined); |
44 | 47 |
|
45 | 48 | setContext<LayoutContext>('headings', writable({})); |
46 | 49 |
|
|
135 | 138 | date: date, |
136 | 139 | lastUpdated: lastUpdated |
137 | 140 | }, |
138 | | - authorData |
| 141 | + authorData.length > 0 |
| 142 | + ? authorData.length === 1 |
| 143 | + ? authorData[0] |
| 144 | + : authorData |
| 145 | + : undefined |
139 | 146 | ) |
140 | 147 | )} |
141 | 148 | </svelte:head> |
|
184 | 191 | <section class="mt-8"> |
185 | 192 | <div class="grid grid-cols-1 gap-12 md:grid-cols-3"> |
186 | 193 | {#each posts.filter((p) => p.title !== title).slice(0, 3) as post} |
187 | | - {@const author = authors.find((a) => a.slug === post.author)} |
188 | | - {#if author} |
| 194 | + {@const postAuthorSlugs = Array.isArray(post.author) |
| 195 | + ? post.author |
| 196 | + : [post.author]} |
| 197 | + {@const primarySlug = postAuthorSlugs[0]} |
| 198 | + {@const postAuthor = |
| 199 | + authors.find((a) => a.slug === primarySlug) || |
| 200 | + authors.find((a) => postAuthorSlugs.includes(a.slug))} |
| 201 | + {#if postAuthor} |
| 202 | + {@const authorNames = postAuthorSlugs |
| 203 | + .map((slug) => authors.find((a) => a.slug === slug)?.name) |
| 204 | + .filter(Boolean)} |
| 205 | + {@const authorLabel = |
| 206 | + authorNames.length > 1 |
| 207 | + ? `${authorNames[0]} +${authorNames.length - 1}` |
| 208 | + : authorNames[0] || postAuthor.name} |
189 | 209 | <Article |
190 | 210 | title={post.title} |
191 | 211 | href={post.href} |
192 | 212 | cover={post.cover} |
193 | 213 | date={post.date} |
194 | 214 | timeToRead={post.timeToRead} |
195 | | - avatar={author.avatar} |
196 | | - author={author.name} |
| 215 | + avatar={postAuthor.avatar} |
| 216 | + author={authorLabel} |
197 | 217 | /> |
198 | 218 | {/if} |
199 | 219 | {/each} |
|
0 commit comments