import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { getPostBySlug, getAdjacentPosts } from '$lib/blog/posts';

export const load: PageServerLoad = ({ params }) => {
	const post = getPostBySlug(params.slug);

	if (!post) {
		error(404, 'Post not found');
	}

	const { previous, next } = getAdjacentPosts(params.slug);

	return { post, previous, next };
};
