forked from payloadcms/payload
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(templates): update config structure in website template to be mo…
…re clear (payloadcms#9161)
- Loading branch information
Showing
6 changed files
with
1,789 additions
and
4,814 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Config } from 'payload' | ||
import { | ||
BoldFeature, | ||
ItalicFeature, | ||
LinkFeature, | ||
ParagraphFeature, | ||
lexicalEditor, | ||
UnderlineFeature, | ||
} from '@payloadcms/richtext-lexical' | ||
|
||
export const defaultLexical: Config['editor'] = lexicalEditor({ | ||
features: () => { | ||
return [ | ||
ParagraphFeature(), | ||
UnderlineFeature(), | ||
BoldFeature(), | ||
ItalicFeature(), | ||
LinkFeature({ | ||
enabledCollections: ['pages', 'posts'], | ||
fields: ({ defaultFields }) => { | ||
const defaultFieldsWithoutUrl = defaultFields.filter((field) => { | ||
if ('name' in field && field.name === 'url') return false | ||
return true | ||
}) | ||
|
||
return [ | ||
...defaultFieldsWithoutUrl, | ||
{ | ||
name: 'url', | ||
type: 'text', | ||
admin: { | ||
condition: ({ linkType }) => linkType !== 'internal', | ||
}, | ||
label: ({ t }) => t('fields:enterURL'), | ||
required: true, | ||
}, | ||
] | ||
}, | ||
}), | ||
] | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { payloadCloudPlugin } from '@payloadcms/payload-cloud' | ||
import { formBuilderPlugin } from '@payloadcms/plugin-form-builder' | ||
import { nestedDocsPlugin } from '@payloadcms/plugin-nested-docs' | ||
import { redirectsPlugin } from '@payloadcms/plugin-redirects' | ||
import { seoPlugin } from '@payloadcms/plugin-seo' | ||
import { searchPlugin } from '@payloadcms/plugin-search' | ||
import { Plugin } from 'payload' | ||
import { revalidateRedirects } from '@/hooks/revalidateRedirects' | ||
import { GenerateTitle, GenerateURL } from '@payloadcms/plugin-seo/types' | ||
import { FixedToolbarFeature, HeadingFeature, lexicalEditor } from '@payloadcms/richtext-lexical' | ||
import { searchFields } from '@/search/fieldOverrides' | ||
import { beforeSyncWithSearch } from '@/search/beforeSync' | ||
|
||
import { Page, Post } from '@/payload-types' | ||
|
||
const generateTitle: GenerateTitle<Post | Page> = ({ doc }) => { | ||
return doc?.title ? `${doc.title} | Payload Website Template` : 'Payload Website Template' | ||
} | ||
|
||
const generateURL: GenerateURL<Post | Page> = ({ doc }) => { | ||
return doc?.slug | ||
? `${process.env.NEXT_PUBLIC_SERVER_URL!}/${doc.slug}` | ||
: process.env.NEXT_PUBLIC_SERVER_URL! | ||
} | ||
|
||
export const plugins: Plugin[] = [ | ||
redirectsPlugin({ | ||
collections: ['pages', 'posts'], | ||
overrides: { | ||
// @ts-expect-error | ||
fields: ({ defaultFields }) => { | ||
return defaultFields.map((field) => { | ||
if ('name' in field && field.name === 'from') { | ||
return { | ||
...field, | ||
admin: { | ||
description: 'You will need to rebuild the website when changing this field.', | ||
}, | ||
} | ||
} | ||
return field | ||
}) | ||
}, | ||
hooks: { | ||
afterChange: [revalidateRedirects], | ||
}, | ||
}, | ||
}), | ||
nestedDocsPlugin({ | ||
collections: ['categories'], | ||
}), | ||
seoPlugin({ | ||
generateTitle, | ||
generateURL, | ||
}), | ||
formBuilderPlugin({ | ||
fields: { | ||
payment: false, | ||
}, | ||
formOverrides: { | ||
fields: ({ defaultFields }) => { | ||
return defaultFields.map((field) => { | ||
if ('name' in field && field.name === 'confirmationMessage') { | ||
return { | ||
...field, | ||
editor: lexicalEditor({ | ||
features: ({ rootFeatures }) => { | ||
return [ | ||
...rootFeatures, | ||
FixedToolbarFeature(), | ||
HeadingFeature({ enabledHeadingSizes: ['h1', 'h2', 'h3', 'h4'] }), | ||
] | ||
}, | ||
}), | ||
} | ||
} | ||
return field | ||
}) | ||
}, | ||
}, | ||
}), | ||
searchPlugin({ | ||
collections: ['posts'], | ||
beforeSync: beforeSyncWithSearch, | ||
searchOverrides: { | ||
fields: ({ defaultFields }) => { | ||
return [...defaultFields, ...searchFields] | ||
}, | ||
}, | ||
}), | ||
payloadCloudPlugin(), | ||
] |