Closed TimDaub closed 3 years ago
How I ended up fixing it for now:
slugify: s => {
s = s.replace(/[^a-zA-Z0-9]+/g, "");
return encodeURIComponent(s);
}
(I ended up replacing all special characters with the empty string. The resulting URI is now: /blog#TheAlgorithmItsWorking
Hey!
I understand the concern. The idea behind the default behavior was to provide a safe (per spec) URL without being opinionated on how the slug should look like, and without requiring an external module either.
I personally use the slugify
function from the string
module on my own blog (see User-Friendly URLs which does something very similar to what you do and works for me, but would also strip the whole title when written in non-latin languages (and also requires an external library) which is why it's not the default.
Hope that makes sense =)
OK, all good. Thanks!
I started using this library on my blog for headlines and my first headline was
/blog#the-algorithm%3B-it's-working!
. But when I shared the link with my users on Telegram and Whatsapp, they didn't end up at the headline's ID.I first thought it had to do with the package's encoding of my "slugification". However, it turns out that Whatsapp and Telegram simply don't count certain letters as part of a link when at the end. Here's an example:
I know that I can simply overwrite the slugification. But would it make sense to make that a default behavior? I was expecting it to generate safe links.