mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
feat: alias option supports regexp, resolve #183
This commit is contained in:
parent
9af855921e
commit
c4aa22c56d
4
dev.html
4
dev.html
@ -19,9 +19,7 @@
|
||||
<script>
|
||||
window.$docsify = {
|
||||
alias: {
|
||||
'/de-de/changelog': '/changelog',
|
||||
'/zh-cn/changelog': '/changelog',
|
||||
'/changelog': 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG'
|
||||
'.*?/changelog': 'https://raw.githubusercontent.com/QingWei-Li/docsify/master/CHANGELOG'
|
||||
},
|
||||
auto2top: true,
|
||||
basePath: '/docs/',
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
import { getPath, isAbsolutePath } from '../util'
|
||||
import { noop } from '../../util/core'
|
||||
|
||||
function getAlias (path, alias) {
|
||||
return alias[path] ? getAlias(alias[path], alias) : path
|
||||
const cached = {}
|
||||
|
||||
function getAlias (path, alias, last) {
|
||||
const match = Object.keys(alias).filter((key) => {
|
||||
const re = cached[key] || (cached[key] = new RegExp(`^${key}$`))
|
||||
return re.test(path) && path !== last
|
||||
})[0]
|
||||
|
||||
return match ? getAlias(path.replace(cached[match], alias[match]), alias, path) : path
|
||||
}
|
||||
|
||||
function getFileName (path) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user