Skip to content

Commit 8ad835c

Browse files
committed
feat(render) nameLink for each route, fixed #99
1 parent 0994663 commit 8ad835c

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

Diff for: src/core/render/compiler.js

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ markdown.renderer = renderer
3434

3535
markdown.init = function (config = {}, base = window.location.pathname) {
3636
contentBase = getBasePath(base)
37-
currentPath = parse().path
3837

3938
if (isFn(config)) {
4039
markdownCompiler = config(marked, renderer)

Diff for: src/core/render/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as tpl from './tpl'
66
import { markdown, sidebar, subSidebar, cover } from './compiler'
77
import { callHook } from '../init/lifecycle'
88
import { getBasePath, getPath, isAbsolutePath } from '../route/util'
9+
import { isPrimitive } from '../util/core'
910

1011
function executeScript () {
1112
const script = dom.findAll('.markdown-section>script')
@@ -47,6 +48,22 @@ function renderMain (html) {
4748
}
4849
}
4950

51+
function renderNameLink (vm) {
52+
const el = dom.getNode('.app-name-link')
53+
const nameLink = vm.config.nameLink
54+
const path = vm.route.path
55+
56+
if (!el) return
57+
58+
if (isPrimitive(vm.config.nameLink)) {
59+
el.setAttribute('href', nameLink)
60+
} else if (typeof nameLink === 'object') {
61+
const match = Object.keys(nameLink).find(key => path.indexOf(key) > -1)
62+
63+
el.setAttribute('href', nameLink[match])
64+
}
65+
}
66+
5067
export function renderMixin (proto) {
5168
proto._renderTo = function (el, content, replace) {
5269
const node = dom.getNode(el)
@@ -120,6 +137,8 @@ export function renderMixin (proto) {
120137

121138
proto._updateRender = function () {
122139
markdown.update()
140+
// render name link
141+
renderNameLink(this)
123142
}
124143
}
125144

Diff for: src/core/render/tpl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function main (config) {
3131
'</button>' +
3232
'<aside class="sidebar">' +
3333
(config.name
34-
? `<h1><a data-nosearch href="${config.nameLink}">${config.name}</a></h1>`
34+
? `<h1><a class="app-name-link" data-nosearch>${config.name}</a></h1>`
3535
: '') +
3636
'<div class="sidebar-nav"></div>' +
3737
'</aside>')

Diff for: src/core/route/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ let lastRoute = {}
3434
export function initRoute (vm) {
3535
normalize()
3636
lastRoute = vm.route = parse()
37+
vm._updateRender()
3738

3839
on('hashchange', _ => {
3940
normalize()

0 commit comments

Comments
 (0)