Files
briannelson.dev/src/collections/Page.ts
2025-10-11 14:51:35 -04:00

66 lines
2.0 KiB
TypeScript

import { MetaDescriptionField, MetaImageField, MetaTitleField, OverviewField, PreviewField } from '@payloadcms/plugin-seo/fields'
import type { CollectionConfig } from 'payload'
import { slugField } from 'payload'
export const Page: CollectionConfig = {
slug: 'pages',
defaultPopulate: {
title: true,
slug: true,
},
admin: {
defaultColumns: ['title', 'slug', 'updatedAt',],
},
fields: [
{
name: 'title',
type: 'text',
required: true,
},
{
type: 'tabs',
tabs: [
{
label: 'Content',
fields: [
{
name: 'richText',
type: 'richText'
},
]
},
{
name: 'meta',
label: 'SEO',
fields: [
OverviewField({
titlePath: 'meta.title',
descriptionPath: 'meta.description',
imagePath: 'meta.image',
}),
MetaTitleField({
hasGenerateFn: true,
}),
MetaImageField({
relationTo: 'media',
}),
MetaDescriptionField({}),
PreviewField({
// if the `generateUrl` function is configured
hasGenerateFn: true,
// field paths to match the target field for data
titlePath: 'meta.title',
descriptionPath: 'meta.description',
}),
],
},
]
},
slugField(),
],
}