fix(build): use default slugify from mdit-vue (#1554)

pull/1557/head
Divyansh Singh 2 years ago committed by GitHub
parent db1c343dfb
commit 8cd1f7c4aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -109,7 +109,6 @@
"@types/compression": "^1.7.2",
"@types/cross-spawn": "^6.0.2",
"@types/debug": "^4.1.7",
"@types/diacritics": "^1.3.1",
"@types/escape-html": "^1.0.2",
"@types/fs-extra": "^9.0.13",
"@types/koa": "^2.13.5",
@ -127,7 +126,6 @@
"conventional-changelog-cli": "^2.2.2",
"cross-spawn": "^7.0.3",
"debug": "^4.3.4",
"diacritics": "^1.3.0",
"enquirer": "^2.3.6",
"esbuild": "^0.15.12",
"escape-html": "^1.0.3",

@ -22,7 +22,6 @@ importers:
'@types/compression': ^1.7.2
'@types/cross-spawn': ^6.0.2
'@types/debug': ^4.1.7
'@types/diacritics': ^1.3.1
'@types/escape-html': ^1.0.2
'@types/fs-extra': ^9.0.13
'@types/koa': ^2.13.5
@ -44,7 +43,6 @@ importers:
conventional-changelog-cli: ^2.2.2
cross-spawn: ^7.0.3
debug: ^4.3.4
diacritics: ^1.3.0
enquirer: ^2.3.6
esbuild: ^0.15.12
escape-html: ^1.0.3
@ -113,7 +111,6 @@ importers:
'@types/compression': 1.7.2
'@types/cross-spawn': 6.0.2
'@types/debug': 4.1.7
'@types/diacritics': 1.3.1
'@types/escape-html': 1.0.2
'@types/fs-extra': 9.0.13
'@types/koa': 2.13.5
@ -131,7 +128,6 @@ importers:
conventional-changelog-cli: 2.2.2
cross-spawn: 7.0.3
debug: 4.3.4_supports-color@9.2.3
diacritics: 1.3.0
enquirer: 2.3.6
esbuild: 0.15.12
escape-html: 1.0.3
@ -685,10 +681,6 @@ packages:
'@types/ms': 0.7.31
dev: true
/@types/diacritics/1.3.1:
resolution: {integrity: sha512-tAH+RY51Zbz7ZSzN7yxQBKEue78U6weZ1UUBNjFoitoLbJGFJCKI7KVHwGsnYo4s2xSFr9KGEkjst2FolpYqyA==}
dev: true
/@types/escape-html/1.0.2:
resolution: {integrity: sha512-gaBLT8pdcexFztLSPRtriHeXY/Kn4907uOCZ4Q3lncFBkheAWOuNt53ypsF8szgxbEJ513UeBzcf4utN0EzEwA==}
dev: true
@ -1654,10 +1646,6 @@ packages:
object-keys: 1.1.1
dev: true
/diacritics/1.3.0:
resolution: {integrity: sha512-wlwEkqcsaxvPJML+rDh/2iS824jbREk6DUMUKkEaSlxdYHeS43cClJtsWglvw2RfeXGm6ohKDqsXteJ5sP5enA==}
dev: true
/dot-prop/5.3.0:
resolution: {integrity: sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==}
engines: {node: '>=8'}

@ -14,9 +14,9 @@ import {
import { sfcPlugin, type SfcPluginOptions } from '@mdit-vue/plugin-sfc'
import { titlePlugin } from '@mdit-vue/plugin-title'
import { tocPlugin, type TocPluginOptions } from '@mdit-vue/plugin-toc'
import { slugify } from '@mdit-vue/shared'
import { IThemeRegistration } from 'shiki'
import { highlight } from './plugins/highlight'
import { slugify } from './plugins/slugify'
import { highlightLinePlugin } from './plugins/highlightLines'
import { lineNumberPlugin } from './plugins/lineNumbers'
import { containerPlugin } from './plugins/containers'
@ -97,7 +97,6 @@ export const createMarkdownRenderer = async (
...options.frontmatter
} as FrontmatterPluginOptions)
.use(headersPlugin, {
slugify,
...options.headers
} as HeadersPluginOptions)
.use(sfcPlugin, {
@ -105,7 +104,6 @@ export const createMarkdownRenderer = async (
} as SfcPluginOptions)
.use(titlePlugin)
.use(tocPlugin, {
slugify,
...options.toc
} as TocPluginOptions)

@ -1,24 +0,0 @@
// string.js slugify drops non ascii chars so we have to
// use a custom implementation here
import { remove as removeDiacritics } from 'diacritics'
// eslint-disable-next-line no-control-regex
const rControl = /[\u0000-\u001f]/g
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g
export const slugify = (str: string): string => {
return (
removeDiacritics(str)
// Remove control characters
.replace(rControl, '')
// Replace special characters
.replace(rSpecial, '-')
// Remove continuous 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()
)
}
Loading…
Cancel
Save