From 281cea895a262e5cb8c3b28cd120da9afa199ba5 Mon Sep 17 00:00:00 2001 From: vaporvee Date: Wed, 30 Oct 2024 04:08:59 +0100 Subject: [PATCH] got all the infos for home --- src/app/page.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index b44298e..f50a7db 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,13 +1,22 @@ -import type { Home } from "@/sanity/sanity.types"; +import type { Home, Author } from "@/sanity/sanity.types"; import { sanityFetch } from "@/sanity/client"; import Link from "next/link"; const HOME_QUERY = `*[_type == "home"]`; +const OWNER_QUERY = (ownerRef: string) => `*[_type == "author" && _id == "${ownerRef}"]`; export default async function IndexPage() { const result = await sanityFetch({ query: HOME_QUERY }); const home: Home | null = result.data.length > 0 ? result.data[0] : null; + let owner: Author | null = null; + if (home?.owner?._ref) { + const ownerQuery = OWNER_QUERY(home.owner._ref); + const ownerResult = await sanityFetch({ query: ownerQuery }); + owner = ownerResult.data.length > 0 ? ownerResult.data[0] : null; + } + + return (
Blog

@@ -15,6 +24,13 @@ export default async function IndexPage() { <>

{home.pagetitle}

{home.subtitle}

+ {owner && ( +
+

Owner:

+

{owner.name}

+

{owner.slug?.current}

+
+ )} ) : (