Skip to content

Commit

Permalink
feat(render) nameLink for each route, fixed #99
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Feb 28, 2017
1 parent 0994663 commit 8ad835c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions src/core/render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -120,6 +137,8 @@ export function renderMixin (proto) {

proto._updateRender = function () {
markdown.update()
// render name link
renderNameLink(this)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/render/tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function main (config) {
'</button>' +
'<aside class="sidebar">' +
(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>' +
'</aside>')
Expand Down
1 change: 1 addition & 0 deletions src/core/route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let lastRoute = {}
export function initRoute (vm) {
normalize()
lastRoute = vm.route = parse()
vm._updateRender()

on('hashchange', _ => {
normalize()
Expand Down

0 comments on commit 8ad835c

Please sign in to comment.