mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
This PR updates the `cms-sanity` example to use: - App Router - TypeScript - Sanity Studio v3 instead of v2 - Embeds the Studio inside the next app on the `/studio` route. - ISR / Data Cache (revalidations through `revalidatePath` while in Live Visual Editing, time-based to match the Sanity API CDN in production). - Support Vercel Visual Editing out of the box. - The new `next-sanity/image` component. - Vercel Speed Insights. - The Sanity Presentation Tool for live content previews. - Sanity Portable Text setup to fully support `@tailwindcss/typography`. - [AI Assist](https://www.sanity.io/docs/ai-assist) - Auto fill in `alt` text on images. - Preset prompts for content creation
117 lines
3.2 KiB
TypeScript
117 lines
3.2 KiB
TypeScript
import Link from "next/link";
|
|
import { Suspense } from "react";
|
|
|
|
import Avatar from "./avatar";
|
|
import CoverImage from "./cover-image";
|
|
import DateComponent from "./date";
|
|
import MoreStories from "./more-stories";
|
|
import Onboarding from "./onboarding";
|
|
import PortableText from "./portable-text";
|
|
|
|
import * as demo from "@/sanity/lib/demo";
|
|
import { sanityFetch } from "@/sanity/lib/fetch";
|
|
import {
|
|
HeroQueryResponse,
|
|
Post,
|
|
SettingsQueryResponse,
|
|
heroQuery,
|
|
settingsQuery,
|
|
} from "@/sanity/lib/queries";
|
|
|
|
function Intro(props: { title: string | null | undefined; description: any }) {
|
|
const title = props.title || demo.title;
|
|
const description = props.description?.length
|
|
? props.description
|
|
: demo.description;
|
|
return (
|
|
<section className="mt-16 mb-16 flex flex-col items-center lg:mb-12 lg:flex-row lg:justify-between">
|
|
<h1 className="text-balance text-6xl font-bold leading-tight tracking-tighter lg:pr-8 lg:text-8xl">
|
|
{title || demo.title}
|
|
</h1>
|
|
<h2 className="text-pretty mt-5 text-center text-lg lg:pl-8 lg:text-left">
|
|
<PortableText
|
|
className="prose-lg"
|
|
value={description?.length ? description : demo.description}
|
|
/>
|
|
</h2>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function HeroPost({
|
|
title,
|
|
slug,
|
|
excerpt,
|
|
coverImage,
|
|
date,
|
|
author,
|
|
}: Pick<
|
|
Post,
|
|
"title" | "coverImage" | "date" | "excerpt" | "author" | "slug"
|
|
>) {
|
|
return (
|
|
<article>
|
|
<Link className="group mb-8 block md:mb-16" href={`/posts/${slug}`}>
|
|
<CoverImage image={coverImage} priority />
|
|
</Link>
|
|
<div className="mb-20 md:mb-28 md:grid md:grid-cols-2 md:gap-x-16 lg:gap-x-8">
|
|
<div>
|
|
<h3 className="text-pretty mb-4 text-4xl leading-tight lg:text-6xl">
|
|
<Link href={`/posts/${slug}`} className="hover:underline">
|
|
{title}
|
|
</Link>
|
|
</h3>
|
|
<div className="mb-4 text-lg md:mb-0">
|
|
<DateComponent dateString={date} />
|
|
</div>
|
|
</div>
|
|
<div>
|
|
{excerpt && (
|
|
<p className="text-pretty mb-4 text-lg leading-relaxed">
|
|
{excerpt}
|
|
</p>
|
|
)}
|
|
{author && <Avatar name={author.name} picture={author.picture} />}
|
|
</div>
|
|
</div>
|
|
</article>
|
|
);
|
|
}
|
|
|
|
export default async function Page() {
|
|
const [settings, heroPost] = await Promise.all([
|
|
sanityFetch<SettingsQueryResponse>({
|
|
query: settingsQuery,
|
|
}),
|
|
sanityFetch<HeroQueryResponse>({ query: heroQuery }),
|
|
]);
|
|
|
|
return (
|
|
<div className="container mx-auto px-5">
|
|
<Intro title={settings?.title} description={settings?.description} />
|
|
{heroPost ? (
|
|
<HeroPost
|
|
title={heroPost.title}
|
|
slug={heroPost.slug}
|
|
coverImage={heroPost.coverImage}
|
|
excerpt={heroPost.excerpt}
|
|
date={heroPost.date}
|
|
author={heroPost.author}
|
|
/>
|
|
) : (
|
|
<Onboarding />
|
|
)}
|
|
{heroPost?._id && (
|
|
<aside>
|
|
<h2 className="mb-8 text-6xl font-bold leading-tight tracking-tighter md:text-7xl">
|
|
More Stories
|
|
</h2>
|
|
<Suspense>
|
|
<MoreStories skip={heroPost._id} limit={100} />
|
|
</Suspense>
|
|
</aside>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|