interface PostData {
	Content: ConstructorOfATypedSvelteComponent;
	title: string;
	date: string;
	author: string;
}

const defaultSlug = 'notFound';

export async function load({ params }) {
	let post;
	try {
		post = await import(`../markdown/${params.slug}.md`);
	} catch {
		post = await import(`../markdown/${defaultSlug}.md`);
	}
	const { title, date, author } = post.metadata;
	const Content = post.default;

	const postData: PostData = {
		Content,
		title,
		date,
		author
	};
	return postData;
}
