payloadcms / plugin-seo

The official SEO plugin for Payload
97 stars 15 forks source link

How to access collection slug inside `generateURL`? #53

Closed christopherpickering closed 1 year ago

christopherpickering commented 1 year ago

Thanks for the great too. I have a (probably very simple...) question about generating the URL with the generateURL: ({ doc }) function.

I would like the generated urls to be like https://example.com/<collection slug>/<doc slug>.

From the doc (generateURL: ({ doc, locale }) => {console.log(doc); returnhttps://example.com/${doc?.fields?.slug?.value}`) I cannot find any info about the parent collection. I'd really like to get its slug in there without adding another dummy field on the collection.

image

Do you know of an easy way? Thanks!

jacobsfletch commented 1 year ago

Hey @christopherpickering this was not possible before, but I just went ahead and added support for it just now! I released v1.0.14-canary.0 just now so you can give it a try before the feature is generally available. Let me know how it goes!

christopherpickering commented 1 year ago

@jacobsfletch thanks a bunch for that, I will try it out and put feedback. :)

christopherpickering commented 1 year ago

@jacobsfletch it works perfectly. Thank you!

jacobsfletch commented 1 year ago

Amazing! I should be able to get a patch version out for that sometime soon. Let me know if you experience anything unexpected as you use continue to use it.