81 lines
1.6 KiB
TypeScript
81 lines
1.6 KiB
TypeScript
import { defineField, defineType } from "sanity";
|
|
|
|
export default defineType({
|
|
name: "project",
|
|
title: "Project",
|
|
type: "document",
|
|
fields: [
|
|
defineField({
|
|
name: "title",
|
|
title: "Title",
|
|
type: "string",
|
|
}),
|
|
defineField({
|
|
name: "subtitle",
|
|
title: "Subtitle",
|
|
type: "string",
|
|
}),
|
|
defineField({
|
|
name: "slug",
|
|
title: "Slug",
|
|
type: "slug",
|
|
options: {
|
|
source: "title",
|
|
maxLength: 96,
|
|
},
|
|
}),
|
|
defineField({
|
|
name: "author",
|
|
title: "Author",
|
|
type: "reference",
|
|
to: { type: "author" },
|
|
}),
|
|
defineField({
|
|
name: "mainImage",
|
|
title: "Main image",
|
|
type: "image",
|
|
options: {
|
|
hotspot: true,
|
|
},
|
|
fields: [
|
|
{
|
|
name: "alt",
|
|
type: "string",
|
|
title: "Alternative Text",
|
|
},
|
|
],
|
|
}),
|
|
defineField({
|
|
name: "categories",
|
|
title: "Categories",
|
|
type: "array",
|
|
of: [{ type: "reference", to: { type: "category" } }],
|
|
}),
|
|
defineField({
|
|
name: "publishedAt",
|
|
title: "Published at",
|
|
type: "datetime",
|
|
}),
|
|
defineField({
|
|
name: "content",
|
|
title: "Body",
|
|
type: "markdown",
|
|
options: {
|
|
imageUrl: (imageAsset) => `${imageAsset.url}`,
|
|
},
|
|
}),
|
|
],
|
|
|
|
preview: {
|
|
select: {
|
|
title: "title",
|
|
author: "author.name",
|
|
media: "mainImage",
|
|
},
|
|
prepare(selection) {
|
|
const { author } = selection;
|
|
return { ...selection, subtitle: author && `by ${author}` };
|
|
},
|
|
},
|
|
});
|