mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-12-03 04:31:20 +08:00
feat(render) nameLink for each route, fixed #99
This commit is contained in:
parent
0994663c5a
commit
8ad835ca26
@ -34,7 +34,6 @@ markdown.renderer = renderer
|
|||||||
|
|
||||||
markdown.init = function (config = {}, base = window.location.pathname) {
|
markdown.init = function (config = {}, base = window.location.pathname) {
|
||||||
contentBase = getBasePath(base)
|
contentBase = getBasePath(base)
|
||||||
currentPath = parse().path
|
|
||||||
|
|
||||||
if (isFn(config)) {
|
if (isFn(config)) {
|
||||||
markdownCompiler = config(marked, renderer)
|
markdownCompiler = config(marked, renderer)
|
||||||
|
@ -6,6 +6,7 @@ import * as tpl from './tpl'
|
|||||||
import { markdown, sidebar, subSidebar, cover } from './compiler'
|
import { markdown, sidebar, subSidebar, cover } from './compiler'
|
||||||
import { callHook } from '../init/lifecycle'
|
import { callHook } from '../init/lifecycle'
|
||||||
import { getBasePath, getPath, isAbsolutePath } from '../route/util'
|
import { getBasePath, getPath, isAbsolutePath } from '../route/util'
|
||||||
|
import { isPrimitive } from '../util/core'
|
||||||
|
|
||||||
function executeScript () {
|
function executeScript () {
|
||||||
const script = dom.findAll('.markdown-section>script')
|
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) {
|
export function renderMixin (proto) {
|
||||||
proto._renderTo = function (el, content, replace) {
|
proto._renderTo = function (el, content, replace) {
|
||||||
const node = dom.getNode(el)
|
const node = dom.getNode(el)
|
||||||
@ -120,6 +137,8 @@ export function renderMixin (proto) {
|
|||||||
|
|
||||||
proto._updateRender = function () {
|
proto._updateRender = function () {
|
||||||
markdown.update()
|
markdown.update()
|
||||||
|
// render name link
|
||||||
|
renderNameLink(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ export function main (config) {
|
|||||||
'</button>' +
|
'</button>' +
|
||||||
'<aside class="sidebar">' +
|
'<aside class="sidebar">' +
|
||||||
(config.name
|
(config.name
|
||||||
? `<h1><a data-nosearch href="${config.nameLink}">${config.name}</a></h1>`
|
? `<h1><a class="app-name-link" data-nosearch>${config.name}</a></h1>`
|
||||||
: '') +
|
: '') +
|
||||||
'<div class="sidebar-nav"></div>' +
|
'<div class="sidebar-nav"></div>' +
|
||||||
'</aside>')
|
'</aside>')
|
||||||
|
@ -34,6 +34,7 @@ let lastRoute = {}
|
|||||||
export function initRoute (vm) {
|
export function initRoute (vm) {
|
||||||
normalize()
|
normalize()
|
||||||
lastRoute = vm.route = parse()
|
lastRoute = vm.route = parse()
|
||||||
|
vm._updateRender()
|
||||||
|
|
||||||
on('hashchange', _ => {
|
on('hashchange', _ => {
|
||||||
normalize()
|
normalize()
|
||||||
|
Loading…
Reference in New Issue
Block a user