@@ -5,7 +5,7 @@ import cssVars from '../util/polyfill/css-vars'
5
5
import * as tpl from './tpl'
6
6
import { markdown , sidebar , subSidebar , cover } from './compiler'
7
7
import { callHook } from '../init/lifecycle'
8
- import { getBasePath , getPath } from '../route/util'
8
+ import { getBasePath , getPath , isResolvePath } from '../route/util'
9
9
10
10
function executeScript ( ) {
11
11
const script = dom . findAll ( '.markdown-section>script' )
@@ -22,6 +22,7 @@ function executeScript () {
22
22
function renderMain ( html ) {
23
23
if ( ! html ) {
24
24
// TODO: Custom 404 page
25
+ html = 'not found'
25
26
}
26
27
27
28
this . _renderTo ( '.markdown-section' , html )
@@ -56,11 +57,13 @@ export function renderMixin (proto) {
56
57
const active = getAndActive ( '.sidebar-nav' , true , true )
57
58
subSidebar ( active , subMaxLevel )
58
59
// bind event
60
+ this . activeLink = active
59
61
scrollActiveSidebar ( )
60
62
61
63
if ( autoHeader && active ) {
62
64
const main = dom . getNode ( '#main' )
63
- if ( main . children [ 0 ] . tagName !== 'H1' ) {
65
+ const firstNode = main . children [ 0 ]
66
+ if ( firstNode && firstNode . tagName !== 'H1' ) {
64
67
const h1 = dom . create ( 'h1' )
65
68
h1 . innerText = active . innerText
66
69
dom . before ( main , h1 )
@@ -75,7 +78,7 @@ export function renderMixin (proto) {
75
78
76
79
proto . _renderMain = function ( text ) {
77
80
callHook ( this , 'beforeEach' , text , result => {
78
- const html = markdown ( result )
81
+ const html = this . isHTML ? result : markdown ( result )
79
82
callHook ( this , 'afterEach' , html , text => renderMain . call ( this , text ) )
80
83
} )
81
84
}
@@ -88,15 +91,20 @@ export function renderMixin (proto) {
88
91
}
89
92
dom . toggleClass ( el , 'add' , 'show' )
90
93
91
- let html = cover ( text )
94
+ let html = this . coverIsHTML ? text : cover ( text )
92
95
const m = html . trim ( ) . match ( '<p><img.*?data-origin="(.*?)"[^a]+alt="(.*?)">([^<]*?)</p>$' )
93
96
94
97
if ( m ) {
95
98
if ( m [ 2 ] === 'color' ) {
96
99
el . style . background = m [ 1 ] + ( m [ 3 ] || '' )
97
100
} else {
101
+ let path = m [ 1 ]
102
+
98
103
dom . toggleClass ( el , 'add' , 'has-mask' )
99
- el . style . backgroundImage = `url(${ getPath ( getBasePath ( this . config . basePath ) , m [ 1 ] ) } )`
104
+ if ( isResolvePath ( m [ 1 ] ) ) {
105
+ path = getPath ( getBasePath ( this . config . basePath ) , m [ 1 ] )
106
+ }
107
+ el . style . backgroundImage = `url(${ path } )`
100
108
}
101
109
html = html . replace ( m [ 0 ] , '' )
102
110
}
@@ -145,7 +153,7 @@ export function initRender (vm) {
145
153
dom . before ( dom . body , navEl )
146
154
147
155
if ( config . themeColor ) {
148
- dom . $ . head += tpl . theme ( config . themeColor )
156
+ dom . $ . head . innerHTML += tpl . theme ( config . themeColor )
149
157
// Polyfll
150
158
cssVars ( config . themeColor )
151
159
}
0 commit comments