diff --git a/routes/blog/[name].tsx b/routes/blog/[name].tsx index caa021b..f52aaa5 100644 --- a/routes/blog/[name].tsx +++ b/routes/blog/[name].tsx @@ -1,10 +1,17 @@ -import { PageProps } from '$fresh/server.ts' -import { BlogCard, blogMock } from ':components/BlogCard.tsx' +import { RouteContext } from '$fresh/server.ts' +import { BlogPost } from ':components/BlogCard.tsx' +import { fetchNews } from ':src/blog/mod.ts' -export default function Projet({ params }: PageProps) { - const article = blogMock.filter(blogEntry => blogEntry.name === params.name)[0] - - return ( - article ? BlogCard(article) :

Article inconnu

- ) +export default async function Blog(_req: Request, { params }: RouteContext) { + try { + const article = await fetchNews('cohabit', params.name) + return BlogPost(article) + } catch { + return ( + <> +

Une erreur est survenue

+

{`Impossible de récupérer l'article "${params.name}"`}.

+ + ) + } }