Gwk-Cultural-Park/schemas/wedding/weddingpost.ts

94 lines
2.6 KiB
TypeScript
Raw Normal View History

2024-09-07 01:40:25 +00:00
// 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: 'weddingpost',
title: 'Wedding Main Page',
icon: TiCalendarOutline,
type: 'document',
fields: [
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: 'coverImage',
2024-09-08 08:25:35 +00:00
title: 'Image',
description: 'Image untuk cover',
type: 'image',
options: {
hotspot: true,
},
2024-09-07 01:40:25 +00:00
}),
defineField({
name: 'posterImage',
title: 'Poster',
type: 'image',
options: {
hotspot: true,
},
}),
defineField({
name: 'galeryImage',
title: 'Galery Fotos',
description: 'Tambahkan galery foto untuk halaman',
type: 'array',
of: [{ type: 'image' }],
options: {
layout: 'grid'
},
}),
defineField({
name: 'content',
title: 'Content Wedding',
type: 'array',
of: [{ type: 'block' }],
}),
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(' ') }
},
},
})