|
|
|
@ -1,25 +1,20 @@ |
|
|
|
|
import type { APIRoute } from 'astro'; |
|
|
|
|
import { getAuthorById, getAuthorIds } from '../../lib/author'; |
|
|
|
|
import { getAuthorById } from '../../lib/author'; |
|
|
|
|
|
|
|
|
|
export async function getStaticPaths() { |
|
|
|
|
const authorIds = await getAuthorIds(); |
|
|
|
|
export const GET: APIRoute = async function ({ params, request, props }) { |
|
|
|
|
const { authorId } = params as { authorId: string }; |
|
|
|
|
|
|
|
|
|
return await Promise.all( |
|
|
|
|
authorIds.map(async (authorId) => { |
|
|
|
|
const authorDetails = await getAuthorById(authorId); |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
params: { authorId }, |
|
|
|
|
props: { |
|
|
|
|
authorDetails: authorDetails?.frontmatter || {}, |
|
|
|
|
if (!authorDetails) { |
|
|
|
|
return new Response(JSON.stringify({ error: 'Not found' }), { |
|
|
|
|
status: 404, |
|
|
|
|
headers: { |
|
|
|
|
'Content-Type': 'application/json', |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
}), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const GET: APIRoute = async function ({ params, request, props }) { |
|
|
|
|
return new Response(JSON.stringify(props.authorDetails), { |
|
|
|
|
return new Response(JSON.stringify(authorDetails?.frontmatter), { |
|
|
|
|
status: 200, |
|
|
|
|
headers: { |
|
|
|
|
'Content-Type': 'application/json', |
|
|
|
|