import type { CollectionConfig } from 'payload' import { lexicalEditor, EXPERIMENTAL_TableFeature } from '@payloadcms/richtext-lexical' import { isAdminOrEditor } from '@/access/isAdminOrEditor' import { isAuthenticatedOrPublished } from '@/access/isAuthenticatedOrPublished' import { slugifyBeforeChange } from '@/hooks/slugify' import { revalidateAfterChange } from '@/hooks/revalidatePath' export const BlogPosts: CollectionConfig = { slug: 'blog-posts', admin: { useAsTitle: 'title', defaultColumns: ['title', 'slug', 'status', 'publishedAt', 'updatedAt'], group: 'Блог', }, versions: { drafts: true }, access: { read: isAuthenticatedOrPublished, create: isAdminOrEditor, update: isAdminOrEditor, delete: isAdminOrEditor, }, hooks: { beforeChange: [slugifyBeforeChange], afterChange: [revalidateAfterChange], }, fields: [ { name: 'title', type: 'text', required: true }, { name: 'slug', type: 'text', unique: true, index: true, admin: { readOnly: true, position: 'sidebar' }, }, { name: 'publishedAt', type: 'date', admin: { position: 'sidebar', date: { pickerAppearance: 'dayAndTime' } }, }, { name: 'hero', type: 'upload', relationTo: 'media' }, { name: 'body', type: 'richText', editor: lexicalEditor({ features: ({ defaultFeatures }) => [...defaultFeatures, EXPERIMENTAL_TableFeature()], }), }, { name: 'excerpt', type: 'textarea' }, { name: 'categories', type: 'relationship', relationTo: 'categories', hasMany: true }, { name: 'tags', type: 'relationship', relationTo: 'tags', hasMany: true }, { name: 'status', type: 'select', defaultValue: 'draft', options: [ { label: 'Draft', value: 'draft' }, { label: 'Published', value: 'published' }, ], admin: { position: 'sidebar' }, }, ], }