-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpage.tsx
More file actions
104 lines (91 loc) · 2.72 KB
/
page.tsx
File metadata and controls
104 lines (91 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import type { Metadata, ResolvingMetadata } from "next";
import { type PortableTextBlock } from "next-sanity";
import { notFound } from "next/navigation";
import PortableText from "@/components/portable-text";
import type {
GuestQueryResult,
GuestQueryWithRelatedResult,
} from "@/sanity/types";
import { sanityFetch } from "@/sanity/lib/live";
import { guestQuery, guestQueryWithRelated } from "@/sanity/lib/queries";
import { resolveOpenGraphImage } from "@/sanity/lib/utils";
import CoverMedia from "@/components/cover-media";
import { BreadcrumbLinks } from "@/components/breadrumb-links";
import UserSocials from "@/components/user-socials";
import UserRelated from "@/components/user-related";
import Avatar from "@/components/avatar";
type Params = Promise<{ slug: string }>;
export async function generateMetadata(
{ params }: { params: Params },
parent: ResolvingMetadata,
): Promise<Metadata> {
const { slug } = await params;
const guest = (
await sanityFetch({
query: guestQuery,
params: { slug },
stega: false,
})
).data as GuestQueryResult;
const previousImages = (await parent).openGraph?.images || [];
const ogImage = resolveOpenGraphImage(guest?.coverImage);
return {
title: guest?.title,
description: guest?.excerpt,
openGraph: {
images: ogImage ? ogImage : previousImages,
},
} satisfies Metadata;
}
export default async function GuestPage({ params }: { params: Params }) {
const { slug } = await params;
const [guest] = (
await Promise.all([
sanityFetch({
query: guestQueryWithRelated,
params: { slug },
}),
])
).map((res) => res.data) as [GuestQueryWithRelatedResult];
if (!guest?._id) {
return notFound();
}
return (
<div className="container px-5 mx-auto">
<BreadcrumbLinks links={[{ title: "Guests", href: "/guests/page/1" }]} />
<div className="w-full flex flex-col gap-4 md:gap-8">
<div className="flex gap-2 md:gap-8">
{guest?.coverImage && (
<div>
<Avatar
coverImage={guest?.coverImage}
imgSize="w-24 h-24 mr-4"
height={96}
width={96}
/>
</div>
)}
<div className="flex flex-col gap-2 md:gap-">
<h1 className="text-xl font-bold leading-tight tracking-tighter text-balance md:text-2xl md:leading-none lg:text-4xl">
{guest.title}
</h1>
{guest?.socials && (
<div className="flex flex-wrap gap-2">
<UserSocials socials={guest.socials} />
</div>
)}
</div>
</div>
<article>
{guest.content?.length && (
<PortableText
className="prose-violet lg:prose-xl dark:prose-invert"
value={guest.content as PortableTextBlock[]}
/>
)}
</article>
</div>
<UserRelated {...guest?.related} />
</div>
);
}