@websolutespa/payload-plugin-seo
v0.1.1
Published
SEO plugin for PayloadCms
Downloads
282
Readme
@websolutespa/payload-plugin-seo
SEO plugin for PayloadCms.
Payload SEO Plugin
A plugin that allows you to manage the meta tags associated with the pages in your site.
Create rules for managing the meta tags of all the documents in specific collections or a global rule for all collections. Use of tokens allows you to add dynamic values to each meta field.
Requirements:
- Payload version 2.28.0 or higher is required.
Installation
npm i @websolutespa/payload-plugin-seo
Usage
import { buildConfig } from 'payload/config';
import seo from '@websolutespa/payload-plugin-seo';
export default buildConfig({
plugins: [
seo({
collections: [
Homepage.slug,
Post.slug,
],
additionalFields: [
{
name: 'robots',
type: 'text',
},
],
customTokens: [
{
name: 'uppercase-title',
replacementFunction: async (req, collection, doc: { title?: string }, locale) => {
if (!doc.title) {
return '';
}
if (locale) {
const fieldConfig = getDataField(collection.fields, 'title');
return fieldConfig.localized ? doc.title[locale.code]?.toUpperCase() : doc.title.toUpperCase();
}
else {
return doc.title.toUpperCase();
}
},
},
],
metatagsRulesAccess: {
read: ({ req: { user } }) => { return Boolean(user); },
create: ({ req: { user } }) => { return Boolean(user); },
update: ({ req: { user } }) => { return Boolean(user); },
delete: ({ req: { user } }) => { return Boolean(user); },
},
qsMetatagsRules: 'seoMetatagsRules',
}),
// The rest of your plugins config goes here
],
});
Plugin options
| Option | Type | Description |
|----------------------|--------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| collections
| string[]
| An array of collection slugs. The creation of a global rule will only affect the meta tags of the collections specified through this option. During the creation of a rule, only collections specified through this option will be selectable. |
| additionalFields
| DataField[]
| An array of additional fields. These fields will be added to the metatags rules collection, so that you can define rules for additional custom meta tags in addition to those provided from the plugin. |
| customTokens
| (SeoToken)[]
| An array of custom tokens objects. Each token has a name
and a replacementFunction
. The function has the following parameters:- req
: Payload request object- collection
: CollectionConfing of the requested document- doc
: the document and all its data - locale
: the locale for which to return the token value. Only present if the request has the locale=ALL parameter set, otherwise this parameter is null. |
| metatagsRulesAccess
| (MetatagsRuleAccess)[]
| Define the access control functions for the metatags rule collection. |
| qsMetatagsRules
| string
| The name of the querystring parameter which needs to be added to the REST API requests to trigger the evaluation of the metatags rules associated with the requested document. |
Features
- allows the creation of rules for managing the meta tags of all the documents in specific collections or a global rule for all collections
- use of tokens allows you to add dynamic values to each meta field
- define custom tokens with custom replacement functions
- custom meta tags can be defined in addition to those provided by the plugin
- this plugin is fully compatible with the official Payload SEO plugin: rules will not override meta tags defined at the document level