Fix beginner roadmaps not working

pull/5494/head
Kamran Ahmed 8 months ago
parent 7f26ce5e2f
commit 5f97ea8e4f
  1. 34
      src/pages/[roadmapId]/index.json.ts

@ -1,11 +1,39 @@
import type { APIRoute } from 'astro'; import type { APIRoute } from 'astro';
export const GET: APIRoute = async function ({ params, request, props }) { export const GET: APIRoute = async function ({ params, url, request, props }) {
const { roadmapId } = params; const { roadmapId: fullRoadmapId } = params;
if (!fullRoadmapId) {
return new Response(
JSON.stringify({
data: null,
error: {
message: 'Roadmap not found',
},
}),
{
status: 500,
headers: {
'Content-Type': 'application/json',
},
},
);
}
// to account for `roadmap/roadmap-beginner.json` files
const roadmapId =
fullRoadmapId?.indexOf('-beginner') !== -1
? fullRoadmapId.replace('-beginner', '')
: fullRoadmapId;
const fileName =
roadmapId === fullRoadmapId
? `${roadmapId}.json`
: `${fullRoadmapId}.json`;
console.log(fileName);
try { try {
const roadmapJson = await import( const roadmapJson = await import(
`../../data/roadmaps/${roadmapId}/${roadmapId}.json` `../../data/roadmaps/${roadmapId}/${fileName}`
); );
return new Response(JSON.stringify(roadmapJson), { return new Response(JSON.stringify(roadmapJson), {

Loading…
Cancel
Save