diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 785f70c..fbc3f08 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -34,7 +34,6 @@ markdown.renderer = renderer markdown.init = function (config = {}, base = window.location.pathname) { contentBase = getBasePath(base) - currentPath = parse().path if (isFn(config)) { markdownCompiler = config(marked, renderer) diff --git a/src/core/render/index.js b/src/core/render/index.js index 4144ada..d6b6893 100644 --- a/src/core/render/index.js +++ b/src/core/render/index.js @@ -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) } } diff --git a/src/core/render/tpl.js b/src/core/render/tpl.js index 6f79159..e2f1ec7 100644 --- a/src/core/render/tpl.js +++ b/src/core/render/tpl.js @@ -31,7 +31,7 @@ export function main (config) { '' + '') diff --git a/src/core/route/index.js b/src/core/route/index.js index 7c4061e..09a14f9 100644 --- a/src/core/route/index.js +++ b/src/core/route/index.js @@ -34,6 +34,7 @@ let lastRoute = {} export function initRoute (vm) { normalize() lastRoute = vm.route = parse() + vm._updateRender() on('hashchange', _ => { normalize()