parent
4f9917bc5c
commit
36e8e6051b
10 changed files with 64 additions and 53 deletions
@ -1,19 +1,10 @@ |
|||||||
type GuideOpenGraphParams = { |
type RoadmapOpenGraphQuery = { |
||||||
type: 'guide'; |
type: 'roadmaps' | 'guides' | 'best-practices'; |
||||||
authorName: string; |
variant?: 'default' | 'image'; |
||||||
authorAvatar?: string; |
resourceId?: string; |
||||||
title: string; |
guideId?: string; |
||||||
description: string; |
|
||||||
}; |
}; |
||||||
|
|
||||||
type RoadmapOpenGraphParams = { |
export function getOpenGraphImageUrl(params: RoadmapOpenGraphQuery) { |
||||||
type: 'roadmap'; |
|
||||||
title: string; |
|
||||||
description: string; |
|
||||||
}; |
|
||||||
|
|
||||||
export function getOpenGraphImageUrl( |
|
||||||
params: GuideOpenGraphParams | RoadmapOpenGraphParams, |
|
||||||
) { |
|
||||||
return `${import.meta.env.PUBLIC_API_URL}/v1-open-graph?${new URLSearchParams(params)}`; |
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