parent
4f9917bc5c
commit
36e8e6051b
10 changed files with 64 additions and 53 deletions
@ -1,19 +1,10 @@ |
||||
type GuideOpenGraphParams = { |
||||
type: 'guide'; |
||||
authorName: string; |
||||
authorAvatar?: string; |
||||
title: string; |
||||
description: string; |
||||
type RoadmapOpenGraphQuery = { |
||||
type: 'roadmaps' | 'guides' | 'best-practices'; |
||||
variant?: 'default' | 'image'; |
||||
resourceId?: string; |
||||
guideId?: string; |
||||
}; |
||||
|
||||
type RoadmapOpenGraphParams = { |
||||
type: 'roadmap'; |
||||
title: string; |
||||
description: string; |
||||
}; |
||||
|
||||
export function getOpenGraphImageUrl( |
||||
params: GuideOpenGraphParams | RoadmapOpenGraphParams, |
||||
) { |
||||
export function getOpenGraphImageUrl(params: RoadmapOpenGraphQuery) { |
||||
return `${import.meta.env.PUBLIC_API_URL}/v1-open-graph?${new URLSearchParams(params)}`; |
||||
} |
||||
|
@ -0,0 +1,28 @@ |
||||
import type { APIRoute } from 'astro'; |
||||
import { getAuthorById, getAuthorIds } from '../../lib/author'; |
||||
|
||||
export async function getStaticPaths() { |
||||
const authorIds = await getAuthorIds(); |
||||
|
||||
return await Promise.all( |
||||
authorIds.map(async (authorId) => { |
||||
const authorDetails = await getAuthorById(authorId); |
||||
|
||||
return { |
||||
params: { authorId }, |
||||
props: { |
||||
authorDetails: authorDetails?.frontmatter || {}, |
||||
}, |
||||
}; |
||||
}), |
||||
); |
||||
} |
||||
|
||||
export const GET: APIRoute = async function ({ params, request, props }) { |
||||
return new Response(JSON.stringify(props.authorDetails), { |
||||
status: 200, |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
}, |
||||
}); |
||||
}; |
Loading…
Reference in new issue