refactor(core): and markdown compiler
This commit is contained in:
parent
30da0d5d46
commit
fe88c154b0
12 changed files with 194 additions and 232 deletions
27
src/core/render/slugify.js
Normal file
27
src/core/render/slugify.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
let cache = {}
|
||||
const re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,.\/:;<=>?@\[\]^`{|}~]/g
|
||||
|
||||
export function slugify (str) {
|
||||
if (typeof str !== 'string') return ''
|
||||
|
||||
let slug = str.toLowerCase().trim()
|
||||
.replace(/<[^>\d]+>/g, '')
|
||||
.replace(re, '')
|
||||
.replace(/\s/g, '-')
|
||||
.replace(/-+/g, '-')
|
||||
.replace(/^(\d)/, '_$1')
|
||||
let count = cache[slug]
|
||||
|
||||
count = cache.hasOwnProperty(slug) ? (count + 1) : 0
|
||||
cache[slug] = count
|
||||
|
||||
if (count) {
|
||||
slug = slug + '-' + count
|
||||
}
|
||||
|
||||
return slug
|
||||
}
|
||||
|
||||
export function clearSlugCache () {
|
||||
cache = {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue