parent
1d04dd9970
commit
9d63306fc9
16 changed files with 229 additions and 191 deletions
@ -1,59 +1,30 @@ |
||||
import type { APIRoute } from 'astro'; |
||||
|
||||
export const GET: APIRoute = async function ({ params, url, request, props }) { |
||||
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; |
||||
export async function getStaticPaths() { |
||||
const roadmapJsons = import.meta.glob('/src/data/roadmaps/**/*.json', { |
||||
eager: true, |
||||
}); |
||||
|
||||
const fileName = |
||||
roadmapId === fullRoadmapId ? `${roadmapId}.json` : `${fullRoadmapId}.json`; |
||||
return Object.keys(roadmapJsons).map((filePath) => { |
||||
const roadmapId = filePath.split('/').pop()?.replace('.json', ''); |
||||
const roadmapJson = roadmapJsons[filePath] as Record<string, any>; |
||||
|
||||
try { |
||||
const roadmapJson = await import( |
||||
/* @vite-ignore */ `../../data/roadmaps/${roadmapId}/${fileName}` |
||||
); |
||||
|
||||
return new Response(JSON.stringify(roadmapJson), { |
||||
status: 200, |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
return { |
||||
params: { |
||||
roadmapId, |
||||
}, |
||||
}); |
||||
} catch (error) { |
||||
return new Response( |
||||
JSON.stringify({ |
||||
data: null, |
||||
error: { |
||||
message: 'Roadmap not found', |
||||
detail: (error as any).message, |
||||
}, |
||||
}), |
||||
{ |
||||
status: 500, |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
}, |
||||
props: { |
||||
roadmapJson: roadmapJson?.default, |
||||
}, |
||||
); |
||||
} |
||||
}; |
||||
}); |
||||
} |
||||
|
||||
export const GET: APIRoute = async function ({ params, request, props }) { |
||||
return new Response(JSON.stringify(props.roadmapJson), { |
||||
status: 200, |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
}, |
||||
}); |
||||
}; |
||||
|
@ -1,33 +1,33 @@ |
||||
import type { APIRoute } from 'astro'; |
||||
|
||||
export const GET: APIRoute = async function ({ params, request, props }) { |
||||
const { bestPracticeId } = params; |
||||
export async function getStaticPaths() { |
||||
const bestPracticeJsons = await import.meta.glob( |
||||
'/src/data/best-practices/**/*.json', |
||||
{ |
||||
eager: true, |
||||
}, |
||||
); |
||||
|
||||
try { |
||||
const roadmapJson = await import( |
||||
`../../../data/best-practices/${bestPracticeId}/${bestPracticeId}.json` |
||||
); |
||||
return Object.keys(bestPracticeJsons).map((filePath) => { |
||||
const bestPracticeId = filePath.split('/').pop()?.replace('.json', ''); |
||||
const bestPracticeJson = bestPracticeJsons[filePath] as Record<string, any>; |
||||
|
||||
return new Response(JSON.stringify(roadmapJson), { |
||||
status: 200, |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
return { |
||||
params: { |
||||
bestPracticeId, |
||||
}, |
||||
}); |
||||
} catch (error) { |
||||
return new Response( |
||||
JSON.stringify({ |
||||
data: null, |
||||
error: { |
||||
message: 'Best Practices not found', |
||||
}, |
||||
}), |
||||
{ |
||||
status: 500, |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
}, |
||||
props: { |
||||
bestPracticeJson: bestPracticeJson?.default, |
||||
}, |
||||
); |
||||
} |
||||
}; |
||||
}); |
||||
} |
||||
|
||||
export const GET: APIRoute = async function ({ params, request, props }) { |
||||
return new Response(JSON.stringify(props.bestPracticeJson), { |
||||
status: 200, |
||||
headers: { |
||||
'content-type': 'application/json', |
||||
}, |
||||
}); |
||||
}; |
||||
|
@ -1,10 +1,12 @@ |
||||
--- |
||||
import { FrownIcon } from 'lucide-react'; |
||||
import { userApi } from '../../../api/user'; |
||||
import AccountLayout from '../../../layouts/AccountLayout.astro'; |
||||
import { UserPublicProfilePage } from '../../../components/UserPublicProfile/UserPublicProfilePage'; |
||||
import OpenSourceBanner from '../../../components/OpenSourceBanner.astro'; |
||||
import Footer from '../../../components/Footer.astro'; |
||||
import { userApi } from '../../api/user'; |
||||
import AccountLayout from '../../layouts/AccountLayout.astro'; |
||||
import { UserPublicProfilePage } from '../../components/UserPublicProfile/UserPublicProfilePage'; |
||||
import OpenSourceBanner from '../../components/OpenSourceBanner.astro'; |
||||
import Footer from '../../components/Footer.astro'; |
||||
|
||||
export const prerender = false; |
||||
|
||||
interface Params extends Record<string, string | undefined> { |
||||
username: string; |
Loading…
Reference in new issue