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

17 lines
458 B
TypeScript
Raw Normal View History

import type { PageServerLoad } from "./$types";
2023-01-01 04:51:53 +05:30
import fetchApi from "$lib/ghost";
export const load: PageServerLoad = async ({ params }) => {
2023-01-01 04:51:53 +05:30
const data = await fetchApi("posts", "&filter=tags:" + params.tag);
2023-01-02 00:20:51 +05:30
const tagsLoop = data.posts[0].tags.map((tag: { slug: string; name: any; }) => {
if (tag.slug === params.tag) {
return tag.name;
}
});
2023-01-01 04:51:53 +05:30
return {
posts: data.posts,
2023-01-02 00:20:51 +05:30
tagName: tagsLoop.filter((tag: any) => tag !== undefined)[0]
}
};