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

27 lines
603 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", "&filter=tags:" + params.tag);
2023-02-03 23:25:33 +05:30
const tagsLoop = !data.error
? data.posts[0].tags.map((tag: { slug: string; name: any }) => {
if (tag.slug === params.tag) {
return tag.name;
}
})
: [];
2023-01-25 22:41:11 +05:30
const tagName = tagsLoop.filter((tag: any) => tag !== undefined)[0];
const meta = {
title: "Blog tag " + tagName
2023-02-03 23:25:33 +05:30
};
2023-01-02 00:20:51 +05:30
2023-01-01 04:51:53 +05:30
return {
2023-01-25 22:41:11 +05:30
posts: data,
tagName: tagName,
...meta
2023-02-03 23:25:33 +05:30
};
}) satisfies PageServerLoad;