website/src/routes/blog/[title]/+page.server.ts

18 lines
442 B
TypeScript
Raw Normal View History

import type { PageServerLoad } from "./$types";
2023-01-25 22:41:11 +05:30
import fetchGhost from "../fetchGhost";
2023-01-25 22:41:11 +05:30
export const load = (async ({ params, fetch }) => {
const data = await fetchGhost("posts/slug/" + params.title);
2023-01-25 22:41:11 +05:30
const allPosts = await fetchGhost("posts");
const meta = {
title: !allPosts.error ? data.posts[0].title : ""
}
2023-01-03 23:28:24 +05:30
2023-01-01 04:51:53 +05:30
return {
2023-01-25 22:41:11 +05:30
post: !allPosts.error ? data.posts[0] : {},
allPosts: allPosts,
...meta
2023-01-01 04:51:53 +05:30
};
2023-01-25 22:41:11 +05:30
}) satisfies PageServerLoad;