feat: alias option supports regexp, resolve #183

This commit is contained in:
qingwei.li 2017-07-10 22:19:55 +08:00
parent 9af855921e
commit c4aa22c56d
No known key found for this signature in database
GPG Key ID: B6DDC2F7AE80B2F4
2 changed files with 10 additions and 5 deletions

View File

@ -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/',

View File

@ -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) {