Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slugify function for vuepress is outdated #16

Open
Dilant opened this issue Sep 17, 2021 · 0 comments
Open

Slugify function for vuepress is outdated #16

Dilant opened this issue Sep 17, 2021 · 0 comments

Comments

@Dilant
Copy link

Dilant commented Sep 17, 2021

Vuepress has updated its slugify function (for both v1 and next/v2):

const rControl = /[\u0000-\u001f]/g
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’–—<>,.?/]+/g
const rCombining = /[\u0300-\u036F]/g

export const slugify = (str: string): string =>
  str
    .normalize('NFKD')
    // Remove accents
    .replace(rCombining, '')
    // Remove control characters
    .replace(rControl, '')
    // Replace special characters
    .replace(rSpecial, '-')
    // Remove continuos separators
    .replace(/-{2,}/g, '-')
    // Remove prefixing and trailing separators
    .replace(/^-+|-+$/g, '')
    // ensure it doesn't start with a number (#121)
    .replace(/^(\d)/, '_$1')
    // lowercase
    .toLowerCase()

It adds steps of normalizing and removing accents, and no longer requires diacritics dependency. Also, rSpecial adds some new characters.

It's time to fix it now, but should we change defaultSlugify function directly or add a new function / config for vuepress preset?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant