statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
104 stars 73 forks source link

Fix to hyphenated taxonomies from uri #156

Closed Alt-Ben closed 1 year ago

Alt-Ben commented 1 year ago

Super tiny change to fix the hyphenated taxonomies in term uris.

what-the-diff[bot] commented 1 year ago

PR Summary

jasonvarga commented 1 year ago

Can you explain the situation this is fixing? This isn't in the core so it might also be happening there.

Alt-Ben commented 1 year ago

Hi Jason!

So I was using hyphenated taxonomies, and the urls that we'd generally use were just 404'ing. For example:

Taxonomy: Foo Bar Slug: /foo-bar Template: foo_bar.antlers.html

The slug wasn't being picked up, once I added the str_replace in, it all worked as expected.

Hopefully that helps - let me know if I've missed anything, or done something wrong!

ryanmitchell commented 1 year ago

While this change works for your use case, I dont think it's going to be sufficient for all (for example when a taxonomy is linked to a collection).

There are a couple of options:

  1. We could just loop over all taxonomies and find where the uri matches... this works on the assumption there arent going to be a load of them so its a quick query.

  2. We add a uri column to the taxonomies table, write an update script and migration, store the uri in the database, and use that for the query.

Either way the findTaxonomyHandleByUri method needs updated with the new logic.

ryanmitchell commented 1 year ago

Ok for now Ive opted for (1) as its the path of least friction for now. Let me know if this works for your use case.

ryanmitchell commented 1 year ago

@Alt-Ben did you get a chance to review this fix?

Alt-Ben commented 1 year ago

Sorry! Just got around to checking - all looks good from my side! Thank you!