/
__layout.svelte
42 lines (33 loc) · 932 Bytes
/
__layout.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<script context="module">
import { getAllPosts, fromEntries } from '$lib/util';
const files = import.meta.glob('./*.{md,svx,svelte.md}');
/**
* @type {import('@sveltejs/kit').Load}
*/
export async function load({ page }) {
const slug = page.path.replace('/posts/', '');
const posts = await getAllPosts(files);
const post = fromEntries(posts)[slug];
if (!post || !post.published) {
return {
status: 404,
error: new Error('Post could not be found')
};
}
return {
props: {
post
}
};
}
</script>
<script>
import PageHead from '$lib/components/PageHead.svelte';
import ArticleTitle from '$lib/components/ArticleTitle.svelte';
import ArticleMeta from '$lib/components/ArticleMeta.svelte';
export let post;
</script>
<PageHead title={post.title} description={post.description} />
<ArticleTitle title={post.title} />
<ArticleMeta author={post.author} date={post.date} />
<slot />