ctolkien / Slugify

Simple Slug / Clean URL generator helper for Microsoft .NET framework / .NET Standard.
MIT License
93 stars 13 forks source link

Option to limit Slug Length #50

Open ntbm opened 1 year ago

ntbm commented 1 year ago

Implements #18

Added Option to Limit Output Slug Length. Default Value is null to not introduce any breaking Changes into the Library.

ctolkien commented 1 year ago

Hi @ntbm - thanks for this!

ctolkien commented 1 year ago

The failing test is an interesting one... normally the lib won't leave trailing -'s but we are specifically asking for a max length....

ntbm commented 1 year ago

The failing test is an interesting one... normally the lib won't leave trailing -'s but we are specifically afking for a max length....

That's why I added it. Handling all the specific edgescases will be a nightmare. So I'd vote to just accept that edge case. Question is if it be best to document it 🤔

poke commented 1 year ago

Would it make sense to make the limiting a bit “smarter” so that it would not break within words if possible?

For example "this is an example" would slugify to "this-is-an-example". But cutting it at 15 characters would result in "this-is-an-exam" which might not be ideal. Instead, there could be some more sophisticated limiting approach which would result in "this-is-an" instead since example doesn’t fit anymore.

ctolkien commented 1 year ago

Would it make sense to make the limiting a bit “smarter” so that it would not break within words if possible?

If there is a fast way of doing that? I imagine you need scan back to find the last non - character within the string limit length.