parent
ed99d97468
commit
b6a6d6394b
3 changed files with 57 additions and 4 deletions
@ -0,0 +1,19 @@ |
|||||||
|
import { type APIContext } from 'astro'; |
||||||
|
import { api } from './api.ts'; |
||||||
|
|
||||||
|
export type GetAIRoadmapBySlugResponse = { |
||||||
|
id: string; |
||||||
|
term: string; |
||||||
|
title: string; |
||||||
|
data: string; |
||||||
|
}; |
||||||
|
|
||||||
|
export function aiRoadmapApi(context: APIContext) { |
||||||
|
return { |
||||||
|
getAIRoadmapBySlug: async function (roadmapSlug: string) { |
||||||
|
return api(context).get<GetAIRoadmapBySlugResponse>( |
||||||
|
`${import.meta.env.PUBLIC_API_URL}/v1-get-ai-roadmap-by-slug/${roadmapSlug}`, |
||||||
|
); |
||||||
|
}, |
||||||
|
}; |
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
--- |
||||||
|
import { aiRoadmapApi } from '../../../api/ai-roadmap'; |
||||||
|
import BaseLayout from '../../../layouts/BaseLayout.astro'; |
||||||
|
import { GenerateRoadmap } from '../../../components/GenerateRoadmap/GenerateRoadmap'; |
||||||
|
|
||||||
|
export const prerender = false; |
||||||
|
|
||||||
|
interface Params extends Record<string, string | undefined> { |
||||||
|
aiRoadmapSlug: string; |
||||||
|
} |
||||||
|
|
||||||
|
const { aiRoadmapSlug } = Astro.params as Params; |
||||||
|
if (!aiRoadmapSlug) { |
||||||
|
return Astro.redirect('/404'); |
||||||
|
} |
||||||
|
|
||||||
|
const aiRoadmapClient = aiRoadmapApi(Astro as any); |
||||||
|
const { response: roadmap, error } = |
||||||
|
await aiRoadmapClient.getAIRoadmapBySlug(aiRoadmapSlug); |
||||||
|
|
||||||
|
let errorMessage = ''; |
||||||
|
if (error || !roadmap) { |
||||||
|
errorMessage = error?.message || 'Error loading AI Roadmap'; |
||||||
|
} |
||||||
|
--- |
||||||
|
|
||||||
|
<BaseLayout title='Roadmap AI'> |
||||||
|
<GenerateRoadmap roadmapId={roadmap?.id} client:load /> |
||||||
|
</BaseLayout> |
Loading…
Reference in new issue