decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.98k stars 3.05k forks source link

Slug option containing multiple consequent dashes not working as expected #2006

Open selrond opened 5 years ago

selrond commented 5 years ago

Describe the bug

When using multiple dashes in slug template of folder collections like this:

slug: "{{year}}_{{month}}_{{day}}_{{hour}}_{{minute}}_{{second}}---{{slug}}"

newly created articles have one dash instead of three (as one would hope).

To Reproduce

Just use the slug template provided above

Expected behavior

I expect slug to be 2019_01_15_08_20_12---sample-article.md

but I'm getting

2019_01_15_08_20_12-sample-article.md

Screenshots

Applicable Versions:

Additional context

This is crucial for me, as I do some string manipulations to generate prettier filenames in Gatsby.

erquhart commented 5 years ago

We trim consequent dashes as they're generally not wanted, but subsequent dashes specified in the slug template should be respected, agreed.

adamwatters commented 5 years ago

First time contributor - hope I did ok!

erquhart commented 5 years ago

I mentioned this on @adamwatters' (awesome) PR, but I missed that this will be a breaking change, as folks' build systems will be configured to handle slugs in the current way. I happened to run into this issue in the deploy preview links PR (#2028), which introduces preview_path, a field that works exactly the same as slug. It was critical for static parts of preview_path to be completely untouched - turned out that addressing this was nowhere near as simple as I thought.

I introduced the path forward in the PR mentioned above, and we'll transition slug to work the same way in 3.0, which is not too far off.

@selrond happy to help you find a workaround - maybe instead of --- as a separator you can use something like -_-? It's ugly, but maybe it could do the trick for now?

selrond commented 5 years ago

@erquhart well, that's unfortunate... I've settled on ___ (three underscores) but this definitely needs to get addressed or at least clearly documented - it's doing something unexpected with no obvious explanation

erquhart commented 5 years ago

Agreed, documenting would help until 3.0, would accept a PR if anyone is up for adding.

stale[bot] commented 5 years ago

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.