import { defineField, defineType } from "sanity"; import { FileText } from "lucide-react"; import meta from "../blocks/shared/meta"; export default defineType({ name: "post", title: "Post", type: "document", icon: FileText, groups: [ { name: "content", title: "Content", }, { name: "seo", title: "SEO", }, { name: "settings", title: "Settings", }, ], fields: [ defineField({ name: "title", title: "Title", type: "string", group: "content", validation: (Rule) => Rule.required(), }), defineField({ name: "slug", title: "Slug", type: "slug", group: "settings", options: { source: "title", maxLength: 96, slugify: (input: string) => input .toLowerCase() .normalize("NFD") .replace(/[\u0300-\u036f]/g, "") .replace(/đ/g, "d") .replace(/Đ/g, "d") .replace(/[^a-z0-9]+/g, "-") .replace(/^-+|-+$/g, "") .slice(0, 96), }, validation: (Rule) => Rule.required(), }), defineField({ name: "excerpt", title: "Excerpt", type: "text", group: "content", }), defineField({ name: "author", title: "Author", type: "reference", group: "settings", to: { type: "author" }, }), defineField({ name: "image", title: "Image", type: "image", group: "settings", options: { hotspot: true, }, fields: [ { name: "alt", type: "string", title: "Alternative Text", }, ], }), defineField({ name: "categories", title: "Categories", type: "array", group: "settings", of: [{ type: "reference", to: { type: "category" } }], }), defineField({ name: "publishedAt", title: "Published At", type: "datetime", group: "settings", initialValue: () => new Date().toISOString(), }), defineField({ name: "featured", title: "Featured Spotlight", type: "boolean", description: "Display this guide in the Hero Featured Spotlight on the Blog Index page", initialValue: false, group: "settings", }), defineField({ name: "body", title: "Body", type: "block-content", group: "content", }), meta, ], preview: { select: { title: "title", author: "author.name", slug: "slug.current", media: "image", featured: "featured", }, prepare(selection) { const { title, author, slug, media, featured } = selection; const prefix = featured ? "⭐ [Featured] " : ""; return { title: `${prefix}${title}`, subtitle: slug ? `/${slug}` : author ? `by ${author}` : undefined, media, }; }, }, });