fixed visual editing again

This commit is contained in:
2024-10-30 03:28:09 +01:00
parent e55ba609da
commit 1e46040d93

View File

@@ -1,28 +1,26 @@
import Link from "next/link"; import Link from "next/link";
import { type SanityDocument } from "next-sanity"; import { type SanityDocument } from "next-sanity";
import { client } from "@/sanity/client"; import { client, sanityFetch } from "@/sanity/client";
import { Post } from "@/sanity/sanity.types";
const POSTS_QUERY = `*[ const POSTS_QUERY = `*[
_type == "post" _type == "post"
&& defined(slug.current) && defined(slug.current)
]|order(publishedAt desc)[0...12]{_id, title, slug, publishedAt}`; ]|order(publishedAt desc)[0...12]{_id, title, slug, publishedAt}`;
const options = { next: { revalidate: 30 } };
export default async function IndexPage() { export default async function IndexPage() {
const posts = await client.fetch<SanityDocument[]>(POSTS_QUERY, {}, options); const posts = (await sanityFetch({ query: POSTS_QUERY, perspective: "published" })).data;
return ( return (
<main className="container mx-auto min-h-screen max-w-3xl p-8"> <main className="container mx-auto min-h-screen max-w-3xl p-8">
<Link href="/">Home</Link> <Link href="/">Home</Link>
<h1 className="text-4xl font-bold mb-8">Blog</h1> <h1 className="text-4xl font-bold mb-8">Blog</h1>
<ul className="flex flex-col gap-y-4"> <ul className="flex flex-col gap-y-4">
{posts.map((post) => ( {posts.map((post: Post) => (
<li className="hover:underline" key={post._id}> <li className="hover:underline" key={post._id}>
<Link href={`blog/${post.slug.current}`}> <Link href={`blog/${post.slug?.current}`}>
<h2 className="text-xl font-semibold">{post.title}</h2> <h2 className="text-xl font-semibold">{post.title}</h2>
<p>{new Date(post.publishedAt).toLocaleDateString()}</p> <p>{new Date(post.publishedAt ?? "").toLocaleDateString()}</p>
</Link> </Link>
</li> </li>
))} ))}