decap-cms
decap-cms copied to clipboard
feat: allow special characters to pass through slugification
Summary
Some of us would like to include / in our slug fields to build nested page structures. This PR allows arbitrary chars to pass through slugification, above and beyond what's allowed by slug.encoding. Useful for / and perhaps for other functionality in future.
Fixes #4963
Test plan
I added new tests for the new parameter I added demonstrating the true and false case. I also updated the dev config.yml with two example collections.
Checklist
Please add a x inside each checkbox:
- [x] I have read the contribution guidelines.
- [x] Code is formatted via running
yarn format. - [x] Tests are passing via running
yarn test. - [x] The status checks are successful (continuous integration). Those can be seen below.
A picture of a cute animal (not mandatory but encouraged)

@erezrokah Hey, is this solution acceptable? Should I go ahead and update the tests?
Sorry @mikestopcontinues, haven't been able to dig into this.
From a quick look at the issue, the problem seems to be scoped to nested collections and preview_path slugification.
It seems that the expected behavior for nested collections is not to slugify the value of {{slug}}, so maybe we don't need an option and only change that behavior for nested collections?
Hi @erezrokah thanks. I was waaay off!
I updated the PR to specifically target preview paths, under two conditions:
collection.has('nested')collection.get('preview_preserve_slash')
(2) is because my use-case is a slug field that supports slashes. Nested collections are cool, but they're really hard to use. First is the GUI or lack thereof, but I also query a separate github repo for content, and the nested directories make it very difficult to do efficiently. If you push the issue, I'll remove preview_preserve_slash as I can hack my way forward via (1), though it ends up making things more buggy for my content co-founder.
You can see both the nested-method and the slug-method at work in the dev config.yml.
Two questions:
- I strip the first and last slash here, as that seems to be the right call. Is it?
- When preserving slashes, I just skip
sanitizeFilename. Seemingly all of the characters it sanitize are sanitized already anyway. I would have used their{sanitize: (char) => replace}interface, except they don't pass what it would have decided, so I would have had to completely reimplement the library just to ignore slashes. Didn't seem worth it.
Hi @mikestopcontinues, I completely forgot we did https://github.com/netlify/netlify-cms/pull/4279 a while back to support the use case described in the issue.
Can you try using {{dirname}} to see if that solves your use case?
Hi @erezrokah
{{dirname}} is a blank field for me. My setup looks like this:
slug: {{fields.slug}}
preview_path: /{{fields.slug}}
And fields.slug is just a regex pattern that matches this-is/a-slug.
@erezrokah Sorry to ping you on this, but it's a blocker for my current site upgrade. Any thoughts?
@erezrokah Sorry to ping you on this, but it's a blocker for my current site upgrade. Any thoughts?
Sorry for the delay @mikestopcontinues. I might not be able to look at this for another week. I would like to separate the use cases:
preview_pathfor nested collections - this should be handled by using{{dirname}}- I'll need to verify it works.preview_pathfor non nested collections. The change here is more risky as it can impact all users.
If this is blocking you should be able to use the generated CMS build from this Deploy Preview, https://deploy-preview-6220--cms-demo.netlify.app/dist/netlify-cms.js
@erezrokah Thanks! For the time being, I'll try the deploy preview. Let me know what I can do to officially move this forward when you can.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@mikestopcontinues are you still interested in moving this forward?
Sorry @martinjagodic, I no longer use Decap.