WIP blog rendering
This commit is contained in:
parent
ec8e45011c
commit
ac4e2d66e0
9
src/routes/[slug]/+page.svelte
Normal file
9
src/routes/[slug]/+page.svelte
Normal file
|
@ -0,0 +1,9 @@
|
|||
<script lang="ts">
|
||||
export let data;
|
||||
</script>
|
||||
|
||||
<article>
|
||||
<h1>{data.title}</h1>
|
||||
<p>Published: {data.date}</p>
|
||||
<svelte:component this={data.content} />
|
||||
</article>
|
11
src/routes/[slug]/+page.ts
Normal file
11
src/routes/[slug]/+page.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
export async function load({ params }) {
|
||||
const post = await import(`../posts/${params.slug}.md`);
|
||||
const { title, date } = post.metadata;
|
||||
const content = post.default;
|
||||
|
||||
return {
|
||||
content,
|
||||
title,
|
||||
date
|
||||
};
|
||||
}
|
16
src/routes/posts/+page.svelte
Normal file
16
src/routes/posts/+page.svelte
Normal file
|
@ -0,0 +1,16 @@
|
|||
<script lang="ts">
|
||||
export let data;
|
||||
</script>
|
||||
|
||||
<ul>
|
||||
{#each data.posts as post}
|
||||
<li>
|
||||
<h2>
|
||||
<a href={post.path}>
|
||||
{post.meta.title}
|
||||
</a>
|
||||
</h2>
|
||||
Published {post.meta.date}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
18
src/routes/posts/+page.ts
Normal file
18
src/routes/posts/+page.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
export async function load() {
|
||||
const allPostFiles = import.meta.glob<SvelteAllProps>('/src/routes/posts/*.md');
|
||||
const iterablePostFiles = Object.entries(allPostFiles);
|
||||
|
||||
const posts = await Promise.all(
|
||||
iterablePostFiles.map(async ([path, resolver]) => {
|
||||
const { metadata } = await resolver();
|
||||
const postPath = path.slice(11, -3);
|
||||
|
||||
return {
|
||||
meta: metadata,
|
||||
path: postPath
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
return { posts };
|
||||
}
|
4
src/routes/posts/test.md
Normal file
4
src/routes/posts/test.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: foo
|
||||
date: 2023
|
||||
---
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 201 KiB |
Binary file not shown.
Before Width: | Height: | Size: 102 KiB |
Loading…
Reference in a new issue