-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generate better slugs for non latin langs (close #45)
- Loading branch information
Showing
6 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// string.js slugify drops non ascii chars so we have to | ||
// use a custom implementation here | ||
const removeDiacritics = require('diacritics').remove | ||
// eslint-disable-next-line no-control-regex | ||
const rControl = /[\u0000-\u001f]/g | ||
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g | ||
|
||
module.exports = function slugify (str) { | ||
return removeDiacritics(str) | ||
// Remove control characters | ||
.replace(rControl, '') | ||
// Replace special characters | ||
.replace(rSpecial, '-') | ||
// Remove continous separators | ||
.replace(/\-{2,}/g, '-') | ||
// Remove prefixing and trailing separtors | ||
.replace(/^\-+|\-+$/g, '') | ||
// lowercase | ||
.toLowerCase() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters