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', |
||||
export async function getStaticPaths() { |
||||
const roadmapJsons = import.meta.glob('/src/data/roadmaps/**/*.json', { |
||||
eager: true, |
||||
}); |
||||
|
||||
return Object.keys(roadmapJsons).map((filePath) => { |
||||
const roadmapId = filePath.split('/').pop()?.replace('.json', ''); |
||||
const roadmapJson = roadmapJsons[filePath] as Record<string, any>; |
||||
|
||||
return { |
||||
params: { |
||||
roadmapId, |
||||
}, |
||||
props: { |
||||
roadmapJson: roadmapJson?.default, |
||||
}, |
||||
); |
||||
}; |
||||
}); |
||||
} |
||||
|
||||
// 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`; |
||||
|
||||
try { |
||||
const roadmapJson = await import( |
||||
/* @vite-ignore */ `../../data/roadmaps/${roadmapId}/${fileName}` |
||||
); |
||||
|
||||
return new Response(JSON.stringify(roadmapJson), { |
||||
export const GET: APIRoute = async function ({ params, request, props }) { |
||||
return new Response(JSON.stringify(props.roadmapJson), { |
||||
status: 200, |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
}, |
||||
}); |
||||
} 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', |
||||
}, |
||||
}, |
||||
); |
||||
} |
||||
}; |
||||
|
@ -1,33 +1,33 @@ |
||||
import type { APIRoute } from 'astro'; |
||||
|
||||
export const GET: APIRoute = async function ({ params, request, props }) { |
||||
const { bestPracticeId } = params; |
||||
|
||||
try { |
||||
const roadmapJson = await import( |
||||
`../../../data/best-practices/${bestPracticeId}/${bestPracticeId}.json` |
||||
export async function getStaticPaths() { |
||||
const bestPracticeJsons = await import.meta.glob( |
||||
'/src/data/best-practices/**/*.json', |
||||
{ |
||||
eager: true, |
||||
}, |
||||
); |
||||
|
||||
return new Response(JSON.stringify(roadmapJson), { |
||||
status: 200, |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
return Object.keys(bestPracticeJsons).map((filePath) => { |
||||
const bestPracticeId = filePath.split('/').pop()?.replace('.json', ''); |
||||
const bestPracticeJson = bestPracticeJsons[filePath] as Record<string, any>; |
||||
|
||||
return { |
||||
params: { |
||||
bestPracticeId, |
||||
}, |
||||
}); |
||||
} catch (error) { |
||||
return new Response( |
||||
JSON.stringify({ |
||||
data: null, |
||||
error: { |
||||
message: 'Best Practices not found', |
||||
props: { |
||||
bestPracticeJson: bestPracticeJson?.default, |
||||
}, |
||||
}), |
||||
{ |
||||
status: 500, |
||||
}; |
||||
}); |
||||
} |
||||
|
||||
export const GET: APIRoute = async function ({ params, request, props }) { |
||||
return new Response(JSON.stringify(props.bestPracticeJson), { |
||||
status: 200, |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
'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