refactor(core): fix route path
This commit is contained in:
parent
8cae16539d
commit
e2b7b976cf
16 changed files with 125 additions and 444 deletions
|
|
@ -1,10 +1,21 @@
|
|||
import * as dom from '../util/dom'
|
||||
import { getAndActive, sticky } from '../event/sidebar'
|
||||
import { scrollActiveSidebar } from '../event/scroll'
|
||||
import { scrollActiveSidebar, scroll2Top } from '../event/scroll'
|
||||
import cssVars from '../util/polyfill/css-vars'
|
||||
import * as tpl from './tpl'
|
||||
import { markdown, sidebar, subSidebar, cover } from './compiler'
|
||||
import { callHook } from '../init/lifecycle'
|
||||
import { getBasePath, getPath } from '../route/util'
|
||||
|
||||
function executeScript () {
|
||||
const script = dom.findAll('.markdown-section>script')
|
||||
.filter(s => !/template/.test(s.type))[0]
|
||||
if (!script) return false
|
||||
const code = script.innerText.trim()
|
||||
if (!code) return false
|
||||
|
||||
window.__EXECUTE_RESULT__ = new Function('return ' + code)()
|
||||
}
|
||||
|
||||
function renderMain (html) {
|
||||
if (!html) {
|
||||
|
|
@ -14,11 +25,21 @@ function renderMain (html) {
|
|||
this._renderTo('.markdown-section', html)
|
||||
// Render sidebar with the TOC
|
||||
!this.config.loadSidebar && this._renderSidebar()
|
||||
// execute script
|
||||
this.config.executeScript && executeScript()
|
||||
|
||||
if (!this.config.executeScript
|
||||
&& typeof window.Vue !== 'undefined'
|
||||
&& !executeScript()) {
|
||||
window.__EXECUTE_RESULT__ = new window.Vue().$mount('#main')
|
||||
}
|
||||
|
||||
if (this.config.auto2top) {
|
||||
setTimeout(() => scroll2Top(this.config.auto2top), 0)
|
||||
}
|
||||
}
|
||||
|
||||
export function renderMixin (Docsify) {
|
||||
const proto = Docsify.prototype
|
||||
|
||||
export function renderMixin (proto) {
|
||||
proto._renderTo = function (el, content, replace) {
|
||||
const node = dom.getNode(el)
|
||||
if (node) node[replace ? 'outerHTML' : 'innerHTML'] = content
|
||||
|
|
@ -54,14 +75,14 @@ export function renderMixin (Docsify) {
|
|||
dom.toggleClass(el, 'add', 'show')
|
||||
|
||||
let html = cover(text)
|
||||
const m = html.trim().match('<p><img[^s]+src="(.*?)"[^a]+alt="(.*?)">([^<]*?)</p>$')
|
||||
const m = html.trim().match('<p><img.*?data-origin="(.*?)"[^a]+alt="(.*?)">([^<]*?)</p>$')
|
||||
|
||||
if (m) {
|
||||
if (m[2] === 'color') {
|
||||
el.style.background = m[1] + (m[3] || '')
|
||||
} else {
|
||||
dom.toggleClass(el, 'add', 'has-mask')
|
||||
el.style.backgroundImage = `url(${m[1]})`
|
||||
el.style.backgroundImage = `url(${getPath(getBasePath(this.config.basePath), m[1])})`
|
||||
}
|
||||
html = html.replace(m[0], '')
|
||||
}
|
||||
|
|
@ -69,13 +90,17 @@ export function renderMixin (Docsify) {
|
|||
this._renderTo('.cover-main', html)
|
||||
sticky()
|
||||
}
|
||||
|
||||
proto._updateRender = function () {
|
||||
markdown.update()
|
||||
}
|
||||
}
|
||||
|
||||
export function initRender (vm) {
|
||||
const config = vm.config
|
||||
|
||||
// Init markdown compiler
|
||||
markdown.init(vm.config.markdown)
|
||||
markdown.init(config.markdown, config.basePath)
|
||||
|
||||
const id = config.el || '#app'
|
||||
const navEl = dom.find('nav') || dom.create('nav')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue