slugify replaceable? #56
Replies: 4 comments 3 replies
|
Good point. What I don't like about I just did some research and found this article that promotes this more universal solution for slug creation. I think it's quite nice: const removeDiacritics = (s) => {
return s
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
}
const generateSlug = (title) => {
return removeDiacritics(title)
.toLowerCase()
.replace(/[^a-z0-9\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-')
.trim()
}
// Usage
console.log(generateSlug('Příliš žluťoučký kůň')) // 'prilis-zlutoucky-kun' |
|
Sorry for chiming in without having the full context. On what level are these slugs used? If they are used in URLs that point to an "item" view (e.g. document, entity, about page), I would argue that stability matters before anything else. Using any library poses more risk in this regard than hard-coding the slug on the data level. We can easily add a Or do we just use the item ID here? That is the most simple and stable approach. If it applies to lower level things that need an address, but are not items on data level (e.g. a lemma of a commentary), hard-coding is of course over the top (and clashes might be hard to avoid). For this, I would pick a simple approach as suggested by @flicksolutions. |
No,
Good catch! Actually in the original version of
Ok, this is already much better. However, there's also a log of slugs with Gendermarkers (e.g. "Künstler:innen") as well as some with brackets (e.g. "Historische Personen (ohne persoenliche Bekanntschaft)"). So we should replace those as well I think... and suddenly we will find ourselves to rewrite the same slugify-function there was at the beginning ^^
Indeed, I did consider hard-coding them myself. The slugs could live alongside the |
Uh oh!
There was an error while loading. Please reload this page.
Could the slugify function be replaced by encodeURIComponent?
It seems to me that it does roughly the same.
All reactions