feat(route): ✨ rewrite and fully implement blog post route
This commit is contained in:
parent
e0bc4c290f
commit
67379d9468
|
@ -1,10 +1,17 @@
|
||||||
import { PageProps } from '$fresh/server.ts'
|
import { RouteContext } from '$fresh/server.ts'
|
||||||
import { BlogCard, blogMock } from ':components/BlogCard.tsx'
|
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]
|
|
||||||
|
|
||||||
|
export default async function Blog(_req: Request, { params }: RouteContext) {
|
||||||
|
try {
|
||||||
|
const article = await fetchNews('cohabit', params.name)
|
||||||
|
return BlogPost(article)
|
||||||
|
} catch {
|
||||||
return (
|
return (
|
||||||
article ? BlogCard(article) : <h3>Article inconnu</h3>
|
<>
|
||||||
|
<h3>Une erreur est survenue</h3>
|
||||||
|
<p>{`Impossible de récupérer l'article "${params.name}"`}.</p>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue