New Addon - BetterSlugs

Hi Cockpit Community,

Cockpit provides a basic mechanism to handle slugs and we have the UniqueSlugs addon that enhances the core by providing uniqueness of slugs, however, and mostly because I have a scenario that requires a few more options I created a new addon that provides the possibility to define complete paths with dynamic tokens (e.g. blogs/[date:Y]/[field:title] or pages/[field:category]/[field:title], etc.)

The full details on addon are on the github page - https://github.com/pauloamgomes/CockpitCMS-BetterSlugs

1 Like

This plugin works great! I’m just confused as to how to actually implement the slugs once they’re generated. How would I navigate to, for example, blogs/2019/newpost ?

From what I understand, the only way to retrieve a single entry in a collection is to use the api and ?filter the GET request or attach a JSON to a POST request.

Hey @ColinTravis, great you liked it… the slugs are just a representation on how you should access information in your frontend, remember that cockpit is a headless CMS. Let’s imagine you have a blog website, and you have a collection named blog, with a title, summary, date, etc… typically each entry should be accessed in form of blogs/<year>/<post-title>. Having that in slug helps you to build your routes in the frontend, that can be usefully mostly if you are using a static site generator like react-static or gatsby, where all blog collection entries are fetched and the routes are built using the slug as path.

Hey @pauloamgomes

I just opened a ticket for BetterSlugs on github:

  • There’s a typo on line 56
  • Slugs only seem to refresh/update if a lug already exists for the entry. If I run refresh, entries that have not been ‘touched’ yet, won’t update.

Thanks @jasonday for reporting and fix

@pauloamgomes can you speak to the other issue - updating/refresh fields that have not been touched? I get an error unless I open each entry and save it, then the refresh works.

Should be fixed, check on the github issue page.