WIP blog rendering

This commit is contained in:
Kaan Barmore-Genç 2023-11-18 22:46:04 -06:00
parent ec8e45011c
commit ac4e2d66e0
Signed by: kaan
GPG key ID: B2E280771CD62FCF
8 changed files with 58 additions and 0 deletions

View 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>

View 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
};
}

View 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
View 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
View 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