Skip to content

Commit 022c47e

Browse files
authored
site: allow multiple blog authors (#9390)
1 parent 1369aa5 commit 022c47e

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

documentation/blog/2023-02-21-streaming-snapshots-sveltekit.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: Streaming, snapshots, and other new features since SvelteKit 1.0
33
description: Exciting improvements in the latest version of SvelteKit
4-
author: Geoff Rich
5-
authorURL: https://geoffrich.net
4+
author: Geoff Rich, Rich Harris
5+
authorURL: https://geoffrich.net, https://twitter.com/Rich_Harris
66
---
77

88
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).

sites/svelte.dev/src/lib/server/blog/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export async function get_blog_data(base = CONTENT_BASE_PATHS.BLOG) {
3535

3636
const { date, date_formatted, slug } = get_date_and_slug(file);
3737
const { metadata, body } = extractFrontmatter(await readFile(`${base}/${file}`, 'utf-8'));
38+
const authors = metadata.author.split(',').map((author) => author.trim());
39+
const authorUrls = metadata.authorURL.split(',').map((author) => author.trim());
3840

3941
blog_posts.push({
4042
date,
@@ -45,10 +47,10 @@ export async function get_blog_data(base = CONTENT_BASE_PATHS.BLOG) {
4547
slug,
4648
title: metadata.title,
4749
file,
48-
author: {
49-
name: metadata.author,
50-
url: metadata.authorURL
51-
},
50+
authors: authors.map((author, i) => ({
51+
name: author,
52+
url: authorUrls[i]
53+
})),
5254
sections: await get_sections(body)
5355
});
5456
}

sites/svelte.dev/src/lib/server/blog/types.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ export interface BlogPost {
77
date_formatted: string;
88
slug: string;
99
file: string;
10-
author: {
10+
authors: {
1111
name: string;
1212
url?: string;
13-
};
13+
}[];
1414
draft: boolean;
1515
content: string;
1616
sections: Section[];

sites/svelte.dev/src/routes/blog/[slug]/+page.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@
2626
<p class="standfirst">{data.post.description}</p>
2727

2828
<p class="byline">
29-
<a href={data.post.author.url}>{data.post.author.name}</a>
29+
{#each data.post.authors as author, i}
30+
{@const show_comma = data.post.authors.length > 2 && i < data.post.authors.length - 1}
31+
{@const show_and = i === data.post.authors.length - 2}
32+
<svelte:element this={author.url ? 'a' : 'span'} href={author.url}
33+
>{author.name}</svelte:element
34+
>{#if show_comma},&nbsp;{/if}
35+
{#if show_and}and&nbsp;{/if}
36+
{/each}
3037
<time datetime={data.post.date}>{data.post.date_formatted}</time>
3138
</p>
3239

0 commit comments

Comments
 (0)