Support for globals
ted-too opened this issue · 1 comments
ted-too commented
Currently the plugin only works on collections but it would be nice if it could work on globals because for example you may have a global for content on a single unique page such as an about us page.
Unless there some caveats with doing so, I think it would be as simple as adding a globals option to the plugin like so:
// src/index.ts
globals: config.globals?.map((global) => {
const { slug } = global;
const isEnabled = seoConfig?.globals?.includes(slug);
if (isEnabled) {
return {
...global,
fields: [...(global?.fields || []), ...seoFields],
};
}
return global;
}),
globals also added in config
// src/types.ts
export type SEOConfig = {
collections?: string[]
globals?: string[]
uploadsCollection?: string
fields?: Partial<Field>[]
generateTitle?: <T = any>(args: { doc: T, locale?: string }) => string | Promise<string>
generateDescription?: <T = any>(args: { doc: T, locale?: string }) => string | Promise<string>
generateImage?: <T = any>(args: { doc: T, locale?: string }) => string | Promise<string>
generateURL?: <T = any>(args: { doc: T, locale?: string }) => string | Promise<string>
}
jacobsfletch commented
Hey @ted-too, good call! I just deployed this in v1.0.7
. Go ahead and bump to this version, and let me know if its not working as expected.
Quick snippet:
yarn add @payloadcms/plugin-seo@^1.0.7