import { createFileRoute } from "@tanstack/react-router";
import { findPosts } from "@/lib/cms";
import Landing from "@/sections/Landing";
import LatestPosts from "@/sections/LatestPosts";

export const Route = createFileRoute("/")({
	loader: async () => {
		// Soft-fail on CMS hiccups so the hero still renders.
		try {
			const { docs } = await findPosts("de", 2);
			return { posts: docs };
		} catch {
			return { posts: [] };
		}
	},
	component: HomePage,
	head: () => ({
		meta: [{ title: "unom - Kreative Webentwicklung" }],
	}),
});

function HomePage() {
	const { posts } = Route.useLoaderData();
	return (
		<>
			<Landing />
			<LatestPosts posts={posts} />
		</>
	);
}
