Gwk-Cultural-Park/schemas/homepagesection/section_homepage.ts

113 lines
2.7 KiB
TypeScript
Raw Normal View History

2024-09-07 01:40:25 +00:00
import { format, parseISO } from 'date-fns'
import { IoDocumentOutline } from 'react-icons/io5'
import { defineField, defineType } from 'sanity'
//pagebuilder schema
import authorType from '../author'
export default defineType({
name: 'homepageSection',
title: 'Homepage Section',
icon: IoDocumentOutline,
type: 'document',
fields: [
defineField({
name: 'title',
title: 'Section Name',
description: 'Nama section',
type: 'string',
validation: (rule) => rule.required(),
}),
defineField({
name: 'heading',
title: 'Heading',
description: 'Heading dari section ini',
type: 'string',
//validation: (rule) => rule.required(),
}),
defineField({
name: 'subheading',
title: 'Sub heading',
description: 'Sub Heading dari section ini',
type: 'string',
}),
defineField({
name: 'imgbackground',
title: 'Background',
description:
'Paste url file photo yang ada di Media untuk background di section ini',
type: 'url',
}),
defineField({
title: 'Text',
name: 'paragraph',
description: 'Teks paragraf dari section ini.',
type: 'array',
of: [{ type: 'block' }],
}),
defineField({
type: 'object',
name: 'CTA',
fieldsets: [{ name: 'ctabutton', title: 'Button' }],
options: {
collapsible: true, // Makes the whole fieldset collapsible
collapsed: true, // Defines if the fieldset should be collapsed by default or not
//columns: 2, // Defines a grid for the fields and how many columns it should have
},
fields: [
defineField({
title: 'Button text',
description: 'Teks pada tombol/button',
name: 'linkText',
type: 'string',
fieldset: 'ctabutton',
}),
{
title: 'URL',
name: 'url',
description: 'Link target',
type: 'string',
fieldset: 'ctabutton',
},
],
}),
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(' ') }
},
},
})