feat(route): rewrite and fully implement blog post route

This commit is contained in:
Julien Oculi 2024-07-02 10:54:13 +02:00
parent e0bc4c290f
commit 67379d9468

View file

@ -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) : <h3>Article inconnu</h3>
)
export default async function Blog(_req: Request, { params }: RouteContext) {
try {
const article = await fetchNews('cohabit', params.name)
return BlogPost(article)
} catch {
return (
<>
<h3>Une erreur est survenue</h3>
<p>{`Impossible de récupérer l'article "${params.name}"`}.</p>
</>
)
}
}