From 022c47edfcb47e369044fba228d90e65cf862783 Mon Sep 17 00:00:00 2001 From: Geoff Rich <4992896+geoffrich@users.noreply.github.com> Date: Sun, 12 Nov 2023 12:09:20 -0800 Subject: [PATCH] site: allow multiple blog authors (#9390) --- .../blog/2023-02-21-streaming-snapshots-sveltekit.md | 4 ++-- sites/svelte.dev/src/lib/server/blog/index.js | 10 ++++++---- sites/svelte.dev/src/lib/server/blog/types.d.ts | 4 ++-- sites/svelte.dev/src/routes/blog/[slug]/+page.svelte | 9 ++++++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/documentation/blog/2023-02-21-streaming-snapshots-sveltekit.md b/documentation/blog/2023-02-21-streaming-snapshots-sveltekit.md index a030e8fc41..b421bd1cc5 100644 --- a/documentation/blog/2023-02-21-streaming-snapshots-sveltekit.md +++ b/documentation/blog/2023-02-21-streaming-snapshots-sveltekit.md @@ -1,8 +1,8 @@ --- title: Streaming, snapshots, and other new features since SvelteKit 1.0 description: Exciting improvements in the latest version of SvelteKit -author: Geoff Rich -authorURL: https://geoffrich.net +author: Geoff Rich, Rich Harris +authorURL: https://geoffrich.net, https://twitter.com/Rich_Harris --- The Svelte team has been hard at work since the release of SvelteKit 1.0. Let’s talk about some of the major new features that have shipped since launch: [streaming non-essential data](https://kit.svelte.dev/docs/load#streaming-with-promises), [snapshots](https://kit.svelte.dev/docs/snapshots), and [route-level config](https://kit.svelte.dev/docs/page-options#config). diff --git a/sites/svelte.dev/src/lib/server/blog/index.js b/sites/svelte.dev/src/lib/server/blog/index.js index d0bcbe96c7..1cd3a16178 100644 --- a/sites/svelte.dev/src/lib/server/blog/index.js +++ b/sites/svelte.dev/src/lib/server/blog/index.js @@ -35,6 +35,8 @@ export async function get_blog_data(base = CONTENT_BASE_PATHS.BLOG) { const { date, date_formatted, slug } = get_date_and_slug(file); const { metadata, body } = extractFrontmatter(await readFile(`${base}/${file}`, 'utf-8')); + const authors = metadata.author.split(',').map((author) => author.trim()); + const authorUrls = metadata.authorURL.split(',').map((author) => author.trim()); blog_posts.push({ date, @@ -45,10 +47,10 @@ export async function get_blog_data(base = CONTENT_BASE_PATHS.BLOG) { slug, title: metadata.title, file, - author: { - name: metadata.author, - url: metadata.authorURL - }, + authors: authors.map((author, i) => ({ + name: author, + url: authorUrls[i] + })), sections: await get_sections(body) }); } diff --git a/sites/svelte.dev/src/lib/server/blog/types.d.ts b/sites/svelte.dev/src/lib/server/blog/types.d.ts index cc2ee90f28..fc922ca54c 100644 --- a/sites/svelte.dev/src/lib/server/blog/types.d.ts +++ b/sites/svelte.dev/src/lib/server/blog/types.d.ts @@ -7,10 +7,10 @@ export interface BlogPost { date_formatted: string; slug: string; file: string; - author: { + authors: { name: string; url?: string; - }; + }[]; draft: boolean; content: string; sections: Section[]; diff --git a/sites/svelte.dev/src/routes/blog/[slug]/+page.svelte b/sites/svelte.dev/src/routes/blog/[slug]/+page.svelte index 158973aebe..c0d50ee251 100644 --- a/sites/svelte.dev/src/routes/blog/[slug]/+page.svelte +++ b/sites/svelte.dev/src/routes/blog/[slug]/+page.svelte @@ -26,7 +26,14 @@

{data.post.description}

- {data.post.author.name} + {#each data.post.authors as author, i} + {@const show_comma = data.post.authors.length > 2 && i < data.post.authors.length - 1} + {@const show_and = i === data.post.authors.length - 2} + {author.name}{#if show_comma}, {/if} + {#if show_and}and {/if} + {/each}