feat(render) nameLink for each route, fixed #99
This commit is contained in:
parent
0994663c5a
commit
8ad835ca26
4 changed files with 21 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ import * as tpl from './tpl'
|
|||
import { markdown, sidebar, subSidebar, cover } from './compiler'
|
||||
import { callHook } from '../init/lifecycle'
|
||||
import { getBasePath, getPath, isAbsolutePath } from '../route/util'
|
||||
import { isPrimitive } from '../util/core'
|
||||
|
||||
function executeScript () {
|
||||
const script = dom.findAll('.markdown-section>script')
|
||||
|
|
@ -47,6 +48,22 @@ function renderMain (html) {
|
|||
}
|
||||
}
|
||||
|
||||
function renderNameLink (vm) {
|
||||
const el = dom.getNode('.app-name-link')
|
||||
const nameLink = vm.config.nameLink
|
||||
const path = vm.route.path
|
||||
|
||||
if (!el) return
|
||||
|
||||
if (isPrimitive(vm.config.nameLink)) {
|
||||
el.setAttribute('href', nameLink)
|
||||
} else if (typeof nameLink === 'object') {
|
||||
const match = Object.keys(nameLink).find(key => path.indexOf(key) > -1)
|
||||
|
||||
el.setAttribute('href', nameLink[match])
|
||||
}
|
||||
}
|
||||
|
||||
export function renderMixin (proto) {
|
||||
proto._renderTo = function (el, content, replace) {
|
||||
const node = dom.getNode(el)
|
||||
|
|
@ -120,6 +137,8 @@ export function renderMixin (proto) {
|
|||
|
||||
proto._updateRender = function () {
|
||||
markdown.update()
|
||||
// render name link
|
||||
renderNameLink(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue