20 lines
591 B
TypeScript
20 lines
591 B
TypeScript
import { error } from '@sveltejs/kit';
|
|
import type { PageServerLoad } from './$types';
|
|
import { getPublishedPostBySlug } from '$lib/server/content';
|
|
|
|
export const load: PageServerLoad = ({ params }) => {
|
|
const post = getPublishedPostBySlug(params.slug);
|
|
if (!post) throw error(404, 'Objava ne obstaja.');
|
|
return {
|
|
post: {
|
|
title: post.title,
|
|
date: (post.publishedAt ?? post.createdAt).toISOString(),
|
|
coverUrl: post.coverImagePath ? `/uploads/${post.coverImagePath}` : null,
|
|
paragraphs: post.body
|
|
.split(/\n{2,}/)
|
|
.map((s) => s.trim())
|
|
.filter(Boolean)
|
|
}
|
|
};
|
|
};
|