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