slugify icon indicating copy to clipboard operation
slugify copied to clipboard

More builtin custom replacements

Open sindresorhus opened this issue 6 years ago • 14 comments

For popular things that makes sense. Suggestions welcome, but I'm not going to add more than maybe 30. So make it worth it.

Don't do a PR. I'll add them all at once when we've decided on what to include.

sindresorhus avatar Apr 29 '18 14:04 sindresorhus

German umlauts (ä, ö, ü) and the letter ß (“sharp s”) are commonly replaced differently:

ä -> ae
ö -> oe
ü -> ue
ß -> ss

So maybe an option for these cases makes sense. If I'm not mistaken the ß is replaced as sz in Switzerland.

Other characters for special treament could be @ and %.

idleberg avatar May 04 '18 13:05 idleberg

So maybe an option for these cases makes sense. If I'm not mistaken the ß is replaced as sz in Switzerland.

I don't intend to internationalize this module, so the target is English.

Other characters for special treament could be @ and %.

👍

sindresorhus avatar May 04 '18 13:05 sindresorhus

Just out of curiosity as I'm a little bit confused about slug styles in general^^ What's the reason behind not supporting i18n? I think it's important and as shown in the example by @idleberg replacing an ä with a doesn't really make sense in the resulting word to a german user. So again, just asking, trying to form a picture of URL slugs and reasonings behind their various possible designs 😉 😁

CanRau avatar Jan 14 '20 05:01 CanRau

@CanRau Unicode slugs can be fine. It really depends on your constraints, both company-wise and tech stack wise. I'm happy to add an option to preserve Unicode characters. It's just not a common request.

https://en.wikipedia.org/wiki/Clean_URL#Slug

sindresorhus avatar Jan 21 '20 15:01 sindresorhus

Hum, now I'm pretty confused and I think the conversation might be confused, too 😅 I thought, for whatever reason, that slugify (this module here) replaces ä-> a but according to replacements.js#L6 it already does the right thing 😳I might've installed npm.im/slugify instead of @sindresorhus/slugify 🤣 what a shame. Now that I tried (again), that's the most likely^^

So german umlauts are properly replaced already and you don't intent to add support for the swiss variation in ß, that makes sense, if that's what you were saying. haha finally 👍

I suffered for nothing 😆 Then I believe (it seems) only https://github.com/sindresorhus/slugify/issues/37 would be missing for @sindresorhus/slugify to be the perfect slugger for me ❤️ 🤞

CanRau avatar Feb 01 '20 05:02 CanRau

So german umlauts are properly replaced already and you don't intent to add support for the swiss variation in ß, that makes sense, if that's what you were saying. haha finally 👍

See my comment in https://github.com/sindresorhus/slugify/pull/38#issuecomment-576731923.

sindresorhus avatar Feb 01 '20 05:02 sindresorhus

I think a common expectation is to have non-alphanumerical symbols map to an empty string by default. Consider for instance a business name like Daisy’s Diner – I don’t want daisy-s-diner as my slug, but rather daisys-diner.

(I half-expected each array in customReplacements to be applied directly to String.replace, but was unsuccessful in passing a regular expression as the first argument. If I could do [/\W/, ''], much would be solved.)

Haraldson avatar May 20 '20 08:05 Haraldson

I think a common expectation is to have non-alphanumerical symbols map to an empty string by default. Consider for instance a business name like Daisy’s Diner – I don’t want daisy-s-diner as my slug, but rather daisys-diner.

I agree with your specific example, but not that all non-alphanumerical symbols should be empty strings. Open a new issue with this and we can figure out a way to improve the output.

sindresorhus avatar May 20 '20 09:05 sindresorhus

@sindresorhus What do you think about removing filler words for better SEO? See https://www.reliablesoft.net/slug/

Read https://twitter.com/deadcoder0904/status/1424627186565193734 for TL;DR

Or should this be done manually? (which makes more sense tbf)

deadcoder0904 avatar Aug 09 '21 07:08 deadcoder0904

It would be nice to have em dash replaced by a regular -. In many fonts there are hardly a visible difference which contributes to many copy paste "issues" from word processors.

fannarsh avatar Oct 06 '22 19:10 fannarsh

Don't have any experience regarding em-dash though it sounds interesting 👏🏼

CanRau avatar Oct 08 '22 17:10 CanRau

My comment was actually meant for the transliterate repo, but for some reason I mixed it up 🤷 That being said, I'm assuming that this https://github.com/sindresorhus/transliterate/issues/11 would take care of my suggestion.

fannarsh avatar Oct 08 '22 22:10 fannarsh

Uh yea I see, so seems that issue got kinda forgotten

CanRau avatar Oct 09 '22 17:10 CanRau

Regarding @Haraldson 's comment on daisy's diner becoming daisys-diner instead of daisy-s-diner, I have an open PR for that in particular, #71 , just fyi for people in this thread.

aegatlin avatar Jan 09 '23 22:01 aegatlin