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 { 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>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue