mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
## Summary Fix typos in code, styles, and documentation across multiple example projects Chores: - Correct variable name typo in the with-slate example (edtorState→editorState) - Fix CSS/SASS class name misspellings (populer→popular, Serach→Search, serachSelector→searchSelector) - Update example documentation and comments to fix English typos (Data SOUCE→SOURCE, accessiblity→accessibility, exchanges, doesn't, deploying, validates, quickly) ### Adding or Updating Examples - [x] The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - [x] Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md Co-authored-by: Joseph <[email protected]>
112 lines
2.7 KiB
TypeScript
112 lines
2.7 KiB
TypeScript
import { DocumentTextIcon } from "@sanity/icons";
|
|
import { format, parseISO } from "date-fns";
|
|
import { defineField, defineType } from "sanity";
|
|
|
|
import authorType from "./author";
|
|
|
|
/**
|
|
* This file is the schema definition for a post.
|
|
*
|
|
* Here you'll be able to edit the different fields that appear when you
|
|
* create or edit a post in the studio.
|
|
*
|
|
* Here you can see the different schema types that are available:
|
|
|
|
https://www.sanity.io/docs/schema-types
|
|
|
|
*/
|
|
|
|
export default defineType({
|
|
name: "post",
|
|
title: "Post",
|
|
icon: DocumentTextIcon,
|
|
type: "document",
|
|
fields: [
|
|
defineField({
|
|
name: "title",
|
|
title: "Title",
|
|
type: "string",
|
|
validation: (rule) => rule.required(),
|
|
}),
|
|
defineField({
|
|
name: "slug",
|
|
title: "Slug",
|
|
type: "slug",
|
|
description: "A slug is required for the post to show up in the preview",
|
|
options: {
|
|
source: "title",
|
|
maxLength: 96,
|
|
isUnique: (value, context) => context.defaultIsUnique(value, context),
|
|
},
|
|
validation: (rule) => rule.required(),
|
|
}),
|
|
defineField({
|
|
name: "content",
|
|
title: "Content",
|
|
type: "array",
|
|
of: [{ type: "block" }],
|
|
}),
|
|
defineField({
|
|
name: "excerpt",
|
|
title: "Excerpt",
|
|
type: "text",
|
|
}),
|
|
defineField({
|
|
name: "coverImage",
|
|
title: "Cover Image",
|
|
type: "image",
|
|
options: {
|
|
hotspot: true,
|
|
aiAssist: {
|
|
imageDescriptionField: "alt",
|
|
},
|
|
},
|
|
fields: [
|
|
{
|
|
name: "alt",
|
|
type: "string",
|
|
title: "Alternative text",
|
|
description: "Important for SEO and accessibility.",
|
|
validation: (rule) => {
|
|
return rule.custom((alt, context) => {
|
|
if ((context.document?.coverImage as any)?.asset?._ref && !alt) {
|
|
return "Required";
|
|
}
|
|
return true;
|
|
});
|
|
},
|
|
},
|
|
],
|
|
validation: (rule) => rule.required(),
|
|
}),
|
|
defineField({
|
|
name: "date",
|
|
title: "Date",
|
|
type: "datetime",
|
|
initialValue: () => new Date().toISOString(),
|
|
}),
|
|
defineField({
|
|
name: "author",
|
|
title: "Author",
|
|
type: "reference",
|
|
to: [{ type: authorType.name }],
|
|
}),
|
|
],
|
|
preview: {
|
|
select: {
|
|
title: "title",
|
|
author: "author.name",
|
|
date: "date",
|
|
media: "coverImage",
|
|
},
|
|
prepare({ title, media, author, date }) {
|
|
const subtitles = [
|
|
author && `by ${author}`,
|
|
date && `on ${format(parseISO(date), "LLL d, yyyy")}`,
|
|
].filter(Boolean);
|
|
|
|
return { title, media, subtitle: subtitles.join(" ") };
|
|
},
|
|
},
|
|
});
|