Gwk-Cultural-Park/schemas/contentheritage.ts
2024-09-07 08:40:25 +07:00

94 lines
2.1 KiB
TypeScript

// import { BookIcon } from '@sanity/icons'
import { format, parseISO } from 'date-fns'
import { TiCalendarOutline } from 'react-icons/ti'
import { defineField, defineType } from 'sanity'
import authorType from './author'
export default defineType({
name: 'contentheritage',
title: 'Content Heritage',
icon: TiCalendarOutline,
type: 'document',
fields: [
defineField({
name: 'headtitle',
title: 'Header Title',
type: 'string',
}),
defineField({
name: 'title',
title: 'Title',
type: 'string',
validation: (rule) => rule.required(),
}),
defineField({
name: 'slug',
title: 'Slug',
type: 'slug',
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: 'coverImage',
title: 'Cover Image',
type: 'array',
of: [
{
name: 'image',
type: 'image',
title: 'Image',
options: {
hotspot: true,
},
fields: [
{
name: 'alt',
type: 'string',
title: 'Alternative text',
},
],
},
],
}),
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(' ') }
},
},
})