sno-blog/sanity/schemas/documents/category.ts
2026-02-02 22:53:36 +03:00

56 lines
1.3 KiB
TypeScript

import { defineField, defineType } from 'sanity'
export const categoryType = defineType({
name: 'category',
title: 'Категория',
type: 'document',
icon: () => '📁',
fields: [
defineField({
name: 'title',
title: 'Название',
type: 'string',
validation: (Rule) => Rule.required().min(2).max(50),
}),
defineField({
name: 'slug',
title: 'Slug',
type: 'slug',
options: {
source: 'title',
maxLength: 96,
},
validation: (Rule) => Rule.required(),
}),
defineField({
name: 'description',
title: 'Описание',
type: 'text',
rows: 3,
}),
defineField({
name: 'color',
title: 'Цвет',
type: 'string',
description: 'HEX цвет для бейджа (например: #FFD700)',
validation: (Rule) =>
Rule.regex(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/, {
name: 'hex color',
invert: false,
}).warning('Используйте HEX формат: #RRGGBB'),
}),
],
preview: {
select: {
title: 'title',
subtitle: 'description',
},
prepare({ title, subtitle }) {
return {
title,
subtitle: subtitle ? subtitle.slice(0, 50) + '...' : '',
}
},
},
})