22 lines
452 B
TypeScript
22 lines
452 B
TypeScript
import { error } from '@sveltejs/kit';
|
|
import type { PageLoad } from './$types';
|
|
|
|
export const load: PageLoad = async ({ params }) => {
|
|
try {
|
|
const post = await import(`$content/post/${params.slug}.md`);
|
|
if (!post) throw error(404);
|
|
const Content = post.default;
|
|
|
|
return {
|
|
metadata: {
|
|
...post.metadata,
|
|
date: new Date(post.metadata.date),
|
|
},
|
|
Content,
|
|
};
|
|
}
|
|
catch {
|
|
error(404, `Could not find post ${params.slug}`)
|
|
}
|
|
}
|