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

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