Exports the fields from the SEO plugin so that they can be used anywhere
inside a collection, new exports:
```ts
import { MetaDescriptionField, MetaImageField, MetaTitleField, OverviewField, PreviewField } from '@payloadcms/plugin-seo/fields'
// Used as fields
MetaImageField({
relationTo: 'media',
hasGenerateFn: true,
})
MetaDescriptionField({
hasGenerateFn: true,
})
MetaTitleField({
hasGenerateFn: true,
})
PreviewField({
hasGenerateFn: true,
titlePath: 'meta.title',
descriptionPath: 'meta.description',
})
OverviewField({
titlePath: 'meta.title',
descriptionPath: 'meta.description',
imagePath: 'meta.image',
})
```
89 lines
2.3 KiB
TypeScript
89 lines
2.3 KiB
TypeScript
import { fileURLToPath } from 'node:url'
|
|
import path from 'path'
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const dirname = path.dirname(filename)
|
|
import type { GenerateDescription, GenerateTitle, GenerateURL } from '@payloadcms/plugin-seo/types'
|
|
import type { Page } from 'plugin-seo/payload-types.js'
|
|
|
|
import { seoPlugin } from '@payloadcms/plugin-seo'
|
|
import { en } from '@payloadcms/translations/languages/en'
|
|
import { es } from '@payloadcms/translations/languages/es'
|
|
|
|
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
|
|
import { devUser } from '../credentials.js'
|
|
import { Media } from './collections/Media.js'
|
|
import { Pages } from './collections/Pages.js'
|
|
import { PagesWithImportedFields } from './collections/PagesWithImportedFields.js'
|
|
import { Users } from './collections/Users.js'
|
|
import { seed } from './seed/index.js'
|
|
|
|
const generateTitle: GenerateTitle<Page> = ({ doc }) => {
|
|
return `Website.com — ${doc?.title}`
|
|
}
|
|
|
|
const generateDescription: GenerateDescription<Page> = ({ doc }) => {
|
|
return doc?.excerpt || 'generated description'
|
|
}
|
|
|
|
const generateURL: GenerateURL<Page> = ({ doc, locale }) => {
|
|
return `https://yoursite.com/${locale ? locale + '/' : ''}${doc?.slug || ''}`
|
|
}
|
|
|
|
export default buildConfigWithDefaults({
|
|
collections: [Users, Pages, Media, PagesWithImportedFields],
|
|
i18n: {
|
|
supportedLanguages: {
|
|
en,
|
|
es,
|
|
},
|
|
translations: {
|
|
es: {
|
|
'plugin-seo': {
|
|
autoGenerate: 'Auto-génerar',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
localization: {
|
|
defaultLocale: 'en',
|
|
fallback: true,
|
|
locales: ['en', 'es', 'de'],
|
|
},
|
|
onInit: async (payload) => {
|
|
await payload.create({
|
|
collection: 'users',
|
|
data: {
|
|
email: devUser.email,
|
|
password: devUser.password,
|
|
},
|
|
})
|
|
|
|
await seed(payload)
|
|
},
|
|
plugins: [
|
|
seoPlugin({
|
|
collections: ['pages'],
|
|
fieldOverrides: {
|
|
title: {
|
|
required: true,
|
|
},
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'ogTitle',
|
|
type: 'text',
|
|
label: 'og:title',
|
|
},
|
|
],
|
|
generateDescription,
|
|
generateTitle,
|
|
generateURL,
|
|
tabbedUI: true,
|
|
uploadsCollection: 'media',
|
|
}),
|
|
],
|
|
typescript: {
|
|
outputFile: path.resolve(dirname, 'payload-types.ts'),
|
|
},
|
|
})
|