Skip to content

Commit

Permalink
feat: alias option supports regexp, resolve #183
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Jul 10, 2017
1 parent 9af8559 commit c4aa22c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 1 addition & 3 deletions dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down
11 changes: 9 additions & 2 deletions src/core/router/history/base.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit c4aa22c

Please sign in to comment.