slugify
slugify copied to clipboard
More builtin custom replacements
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.
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 %
.
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 %.
👍
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 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
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 ❤️ 🤞
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.
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.)
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 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)
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.
Don't have any experience regarding em-dash though it sounds interesting 👏🏼
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.
Uh yea I see, so seems that issue got kinda forgotten
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.