import { RouteContext } from '$fresh/server.ts'
import { BlogPost } from ':components/BlogCard.tsx'
import { fetchNews } from ':src/blog/mod.ts'

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>
			</>
		)
	}
}
