I find it very time-consuming and error-prone to maintain the SEO related fields such as alternate hreflang because I need the other locales / slug of each page / collection.
I can query
/api/pages?locales=all
but it returns everything which is a way too much, I only need the id, the slug field and title/description. Does anyone has a good approach to solve this? For now, I'm querying each collection and each page by id but it takes a while and I assume, it could be way faster.
Hey @wiesson, wondering if a custom endpoint would work for you?
Sure!
Any example I could have a look at?
Collections can have custom endpoints, check out the
endpoints
property here (
https://payloadcms.com/docs/configuration/collections#options).
With it you can open a custom endpoint and use req.payload to use the local api. Fetch with payload.find({ collection: 'pages', locale: 'all' }) and then trim back the response for your endpoint. Alternatively you could even access the underlying mongoose model to make the query, i.e. payload.collections.['your-collection-slug-to-access'].Model().
ah, wonderful! Should be built-in 🙂 (or available via the SEO plugin)
Yeah not a bad idea!
/solved
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.