fix(static): file path
This commit is contained in:
parent
d9d9d114f4
commit
082c68ecee
7 changed files with 151 additions and 160 deletions
144
lib/docsify.js
144
lib/docsify.js
|
|
@ -362,16 +362,21 @@ function main(config) {
|
|||
/**
|
||||
* Cover Page
|
||||
*/
|
||||
function cover() {
|
||||
function cover(ref) {
|
||||
var style = ref.style;
|
||||
var text = ref.text;
|
||||
var hasMask = ref.hasMask;
|
||||
|
||||
var SL = ', 100%, 85%';
|
||||
var bgc =
|
||||
'linear-gradient(to left bottom, ' +
|
||||
"hsl(" + (Math.floor(Math.random() * 255) + SL) + ") 0%," +
|
||||
"hsl(" + (Math.floor(Math.random() * 255) + SL) + ") 100%)";
|
||||
style =
|
||||
style ||
|
||||
'background: linear-gradient(to left bottom, ' +
|
||||
"hsl(" + (Math.floor(Math.random() * 255) + SL) + ") 0%," +
|
||||
"hsl(" + (Math.floor(Math.random() * 255) + SL) + ") 100%)";
|
||||
|
||||
return (
|
||||
"<section class=\"cover show\" style=\"background: " + bgc + "\">" +
|
||||
'<div class="cover-main"><!--cover--></div>' +
|
||||
"<section class=\"cover show " + (hasMask ? ' has-mask' : '') + "\" style=\"" + style + "\">" +
|
||||
"<div class=\"cover-main\">" + text + "</div>" +
|
||||
'<div class="mask"></div>' +
|
||||
'</section>'
|
||||
)
|
||||
|
|
@ -3335,11 +3340,7 @@ function getAndRemoveConfig(str) {
|
|||
str = str
|
||||
.replace(/^'/, '')
|
||||
.replace(/'$/, '')
|
||||
<<<<<<< HEAD
|
||||
.replace(/(?:^|\s):([\w-]+)=?([\w-]+)?/g, function (m, key, value) {
|
||||
=======
|
||||
.replace(/:([\w-]+)=?([\w-]+)?/g, function (m, key, value) {
|
||||
>>>>>>> [build] 4.8.6
|
||||
config[key] = (value && value.replace(/"/g, '')) || true;
|
||||
return ''
|
||||
})
|
||||
|
|
@ -3487,10 +3488,7 @@ Compiler.prototype.compileEmbed = function compileEmbed (href, title) {
|
|||
embed = compileMedia[type].call(this, href, title);
|
||||
embed.type = type;
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
embed.fragment = config.fragment;
|
||||
=======
|
||||
>>>>>>> [build] 4.8.6
|
||||
|
||||
return embed
|
||||
}
|
||||
|
|
@ -3641,26 +3639,29 @@ Compiler.prototype._initRenderer = function _initRenderer () {
|
|||
|
||||
return ("<img src=\"" + url + "\"data-origin=\"" + href + "\" alt=\"" + text + "\"" + attrs + ">")
|
||||
};
|
||||
<<<<<<< HEAD
|
||||
origin.list = renderer.list = function (body, ordered, start) {
|
||||
var isTaskList = /<li class="task-list-item">/.test(body.split('class="task-list"')[0]);
|
||||
var isTaskList = /<li class="task-list-item">/.test(
|
||||
body.split('class="task-list"')[0]
|
||||
);
|
||||
var isStartReq = start && start > 1;
|
||||
var tag = ordered ? 'ol' : 'ul';
|
||||
var tagAttrs = [
|
||||
(isTaskList ? 'class="task-list"' : ''),
|
||||
(isStartReq ? ("start=\"" + start + "\"") : '')
|
||||
].join(' ').trim();
|
||||
isTaskList ? 'class="task-list"' : '',
|
||||
isStartReq ? ("start=\"" + start + "\"") : ''
|
||||
]
|
||||
.join(' ')
|
||||
.trim();
|
||||
|
||||
return ("<" + tag + " " + tagAttrs + ">" + body + "</" + tag + ">")
|
||||
};
|
||||
origin.listitem = renderer.listitem = function (text) {
|
||||
var isTaskItem = /^(<input.*type="checkbox"[^>]*>)/.test(text);
|
||||
var html = isTaskItem ? ("<li class=\"task-list-item\"><label>" + text + "</label></li>") : ("<li>" + text + "</li>");
|
||||
var html = isTaskItem ?
|
||||
("<li class=\"task-list-item\"><label>" + text + "</label></li>") :
|
||||
("<li>" + text + "</li>");
|
||||
|
||||
return html
|
||||
};
|
||||
=======
|
||||
>>>>>>> [build] 4.8.6
|
||||
|
||||
renderer.origin = origin;
|
||||
|
||||
|
|
@ -3719,13 +3720,40 @@ Compiler.prototype.article = function article (text) {
|
|||
/**
|
||||
* Compile cover page
|
||||
*/
|
||||
Compiler.prototype.cover = function cover$$1 (text) {
|
||||
var cacheToc = this.toc.slice();
|
||||
var html = this.compile(text);
|
||||
Compiler.prototype.cover = function cover$$1 (text, isHTML) {
|
||||
if ( isHTML === void 0 ) isHTML = false;
|
||||
|
||||
this.toc = cacheToc.slice();
|
||||
var html = text;
|
||||
if (!isHTML) {
|
||||
var cacheToc = this.toc.slice();
|
||||
html = this.compile(text);
|
||||
this.toc = cacheToc.slice();
|
||||
}
|
||||
|
||||
return html
|
||||
var m = html
|
||||
.trim()
|
||||
.match('<p><img.*?data-origin="(.*?)"[^a]+alt="(.*?)">([^<]*?)</p>$');
|
||||
var style = '';
|
||||
var hasMask = false;
|
||||
if (m) {
|
||||
if (m[2] === 'color') {
|
||||
style = "background: " + (m[1] + (m[3] || ''));
|
||||
} else {
|
||||
var path = m[1];
|
||||
hasMask = true;
|
||||
if (!isAbsolutePath(m[1])) {
|
||||
path = getPath(this.router.getBasePath(), m[1]);
|
||||
}
|
||||
style = "background-image: url(" + path + "); background-size: cover; background-position: center center;";
|
||||
}
|
||||
html = html.replace(m[0], '');
|
||||
}
|
||||
|
||||
return cover({
|
||||
style: style,
|
||||
hasMask: hasMask,
|
||||
text: html
|
||||
})
|
||||
};
|
||||
|
||||
var title = $.title;
|
||||
|
|
@ -3736,12 +3764,9 @@ function btn(el) {
|
|||
var toggle = function (_) { return body.classList.toggle('close'); };
|
||||
|
||||
el = getNode(el);
|
||||
<<<<<<< HEAD
|
||||
if (el == null) {
|
||||
return
|
||||
}
|
||||
=======
|
||||
>>>>>>> [build] 4.8.6
|
||||
on(el, 'click', function (e) {
|
||||
e.stopPropagation();
|
||||
toggle();
|
||||
|
|
@ -3757,13 +3782,9 @@ function btn(el) {
|
|||
|
||||
function collapse(el) {
|
||||
el = getNode(el);
|
||||
<<<<<<< HEAD
|
||||
if (el == null) {
|
||||
return
|
||||
}
|
||||
=======
|
||||
|
||||
>>>>>>> [build] 4.8.6
|
||||
on(el, 'click', function (ref) {
|
||||
var target = ref.target;
|
||||
|
||||
|
|
@ -3801,15 +3822,10 @@ function sticky() {
|
|||
*/
|
||||
function getAndActive(router, el, isParent, autoTitle) {
|
||||
el = getNode(el);
|
||||
<<<<<<< HEAD
|
||||
var links = [];
|
||||
if (el != null) {
|
||||
links = findAll(el, 'a');
|
||||
}
|
||||
=======
|
||||
|
||||
var links = findAll(el, 'a');
|
||||
>>>>>>> [build] 4.8.6
|
||||
var hash = decodeURI(router.toURL(router.getCurrentPath()));
|
||||
var target;
|
||||
|
||||
|
|
@ -4012,14 +4028,10 @@ function scrollActiveSidebar(router) {
|
|||
coverHeight = cover ? cover.offsetHeight : 0;
|
||||
|
||||
var sidebar = getNode('.sidebar');
|
||||
<<<<<<< HEAD
|
||||
var lis = [];
|
||||
if (sidebar != null) {
|
||||
lis = findAll(sidebar, 'li');
|
||||
}
|
||||
=======
|
||||
var lis = findAll(sidebar, 'li');
|
||||
>>>>>>> [build] 4.8.6
|
||||
|
||||
for (var i = 0, len = lis.length; i < len; i += 1) {
|
||||
var li = lis[i];
|
||||
|
|
@ -4103,14 +4115,13 @@ function walkFetchEmbed(ref, cb) {
|
|||
if (token.embed.type === 'markdown') {
|
||||
embedToken = compile.lexer(text);
|
||||
} else if (token.embed.type === 'code') {
|
||||
<<<<<<< HEAD
|
||||
if (token.embed.fragment) {
|
||||
var fragment = token.embed.fragment;
|
||||
var pattern = new RegExp(("(?:###|\\/\\/\\/)\\s*\\[" + fragment + "\\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[" + fragment + "\\]"));
|
||||
text = ((text.match(pattern) || [])[1] || '').trim();
|
||||
var pattern = new RegExp(
|
||||
("(?:###|\\/\\/\\/)\\s*\\[" + fragment + "\\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[" + fragment + "\\]")
|
||||
);
|
||||
text = ((text.match(pattern) || [])[1] || '').trim();
|
||||
}
|
||||
=======
|
||||
>>>>>>> [build] 4.8.6
|
||||
embedToken = compile.lexer(
|
||||
'```' +
|
||||
token.embed.lang +
|
||||
|
|
@ -4376,30 +4387,10 @@ function renderMixin(proto) {
|
|||
}
|
||||
toggleClass(el, 'add', 'show');
|
||||
|
||||
var html = this.coverIsHTML ? text : this.compiler.cover(text);
|
||||
var html = this.compiler.cover(text, this.coverIsHTML);
|
||||
|
||||
var m = html
|
||||
.trim()
|
||||
.match('<p><img.*?data-origin="(.*?)"[^a]+alt="(.*?)">([^<]*?)</p>$');
|
||||
this._renderTo('.cover-placeholder', html, true);
|
||||
|
||||
if (m) {
|
||||
if (m[2] === 'color') {
|
||||
el.style.background = m[1] + (m[3] || '');
|
||||
} else {
|
||||
var path = m[1];
|
||||
|
||||
toggleClass(el, 'add', 'has-mask');
|
||||
if (!isAbsolutePath(m[1])) {
|
||||
path = getPath(this.router.getBasePath(), m[1]);
|
||||
}
|
||||
el.style.backgroundImage = "url(" + path + ")";
|
||||
el.style.backgroundSize = 'cover';
|
||||
el.style.backgroundPosition = 'center center';
|
||||
}
|
||||
html = html.replace(m[0], '');
|
||||
}
|
||||
|
||||
this._renderTo('.cover-main', html);
|
||||
sticky();
|
||||
};
|
||||
|
||||
|
|
@ -4429,8 +4420,9 @@ function initRender(vm) {
|
|||
if (config.repo) {
|
||||
html += corner(config.repo);
|
||||
}
|
||||
|
||||
if (config.coverpage) {
|
||||
html += cover();
|
||||
html += '<div class=cover-placeholder></div>';
|
||||
}
|
||||
|
||||
if (config.logo) {
|
||||
|
|
@ -4490,9 +4482,11 @@ function getAlias(path, alias, last) {
|
|||
}
|
||||
|
||||
function getFileName(path, ext) {
|
||||
return new RegExp(("\\.(" + (ext.replace(/^\./, '')) + "|html)$"), 'g').test(path) ?
|
||||
return /\.\w+$/.test(path) ?
|
||||
path :
|
||||
/\/$/g.test(path) ? (path + "README" + ext) : ("" + path + ext)
|
||||
/\/$/g.test(path) ?
|
||||
(path + "README" + ext) :
|
||||
("" + path + ext)
|
||||
}
|
||||
|
||||
var History = function History(config) {
|
||||
|
|
@ -5075,6 +5069,7 @@ function initGlobalAPI () {
|
|||
dom: dom,
|
||||
get: get,
|
||||
slugify: slugify,
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
version: '4.9.1'
|
||||
=======
|
||||
|
|
@ -5084,6 +5079,9 @@ function initGlobalAPI () {
|
|||
version: '4.8.6'
|
||||
>>>>>>> [build] 4.8.6
|
||||
>>>>>>> [build] 4.8.6
|
||||
=======
|
||||
version: '4.9.0'
|
||||
>>>>>>> fix(static): file path
|
||||
};
|
||||
window.DocsifyCompiler = Compiler;
|
||||
window.marked = marked;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
(function () {
|
||||
var INDEXS = {};
|
||||
|
||||
<<<<<<< HEAD
|
||||
var LOCAL_STORAGE = {
|
||||
EXPIRE_KEY: 'docsify.search.expires',
|
||||
INDEX_KEY: 'docsify.search.index'
|
||||
|
|
@ -14,8 +13,6 @@ function resolveIndexKey(namespace) {
|
|||
return namespace ? ((LOCAL_STORAGE.INDEX_KEY) + "/" + namespace) : LOCAL_STORAGE.INDEX_KEY
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> [build] 4.8.6
|
||||
function escapeHtml(string) {
|
||||
var entityMap = {
|
||||
'&': '&',
|
||||
|
|
@ -49,15 +46,9 @@ function getAllPaths(router) {
|
|||
return paths
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
function saveData(maxAge, expireKey, indexKey) {
|
||||
localStorage.setItem(expireKey, Date.now() + maxAge);
|
||||
localStorage.setItem(indexKey, JSON.stringify(INDEXS));
|
||||
=======
|
||||
function saveData(maxAge) {
|
||||
localStorage.setItem('docsify.search.expires', Date.now() + maxAge);
|
||||
localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS));
|
||||
>>>>>>> [build] 4.8.6
|
||||
}
|
||||
|
||||
function genIndex(path, content, router, depth) {
|
||||
|
|
@ -175,7 +166,6 @@ function search(query) {
|
|||
|
||||
function init$1(config, vm) {
|
||||
var isAuto = config.paths === 'auto';
|
||||
<<<<<<< HEAD
|
||||
|
||||
var expireKey = resolveExpireKey(config.namespace);
|
||||
var indexKey = resolveIndexKey(config.namespace);
|
||||
|
|
@ -183,11 +173,6 @@ function init$1(config, vm) {
|
|||
var isExpired = localStorage.getItem(expireKey) < Date.now();
|
||||
|
||||
INDEXS = JSON.parse(localStorage.getItem(indexKey));
|
||||
=======
|
||||
var isExpired = localStorage.getItem('docsify.search.expires') < Date.now();
|
||||
|
||||
INDEXS = JSON.parse(localStorage.getItem('docsify.search.index'));
|
||||
>>>>>>> [build] 4.8.6
|
||||
|
||||
if (isExpired) {
|
||||
INDEXS = {};
|
||||
|
|
@ -208,11 +193,7 @@ function init$1(config, vm) {
|
|||
.get(vm.router.getFile(path), false, vm.config.requestHeaders)
|
||||
.then(function (result) {
|
||||
INDEXS[path] = genIndex(path, result, vm.router, config.depth);
|
||||
<<<<<<< HEAD
|
||||
len === ++count && saveData(config.maxAge, expireKey, indexKey);
|
||||
=======
|
||||
len === ++count && saveData(config.maxAge);
|
||||
>>>>>>> [build] 4.8.6
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -346,12 +327,8 @@ var CONFIG = {
|
|||
paths: 'auto',
|
||||
depth: 2,
|
||||
maxAge: 86400000, // 1 day
|
||||
<<<<<<< HEAD
|
||||
hideOtherSidebarContent: false,
|
||||
namespace: undefined
|
||||
=======
|
||||
hideOtherSidebarContent: false
|
||||
>>>>>>> [build] 4.8.6
|
||||
};
|
||||
|
||||
var install = function (hook, vm) {
|
||||
|
|
@ -367,10 +344,7 @@ var install = function (hook, vm) {
|
|||
CONFIG.noData = opts.noData || CONFIG.noData;
|
||||
CONFIG.depth = opts.depth || CONFIG.depth;
|
||||
CONFIG.hideOtherSidebarContent = opts.hideOtherSidebarContent || CONFIG.hideOtherSidebarContent;
|
||||
<<<<<<< HEAD
|
||||
CONFIG.namespace = opts.namespace || CONFIG.namespace;
|
||||
=======
|
||||
>>>>>>> [build] 4.8.6
|
||||
}
|
||||
|
||||
var isAuto = CONFIG.paths === 'auto';
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ function mainTpl(config) {
|
|||
html += tpl.corner(config.repo)
|
||||
}
|
||||
if (config.coverpage) {
|
||||
html += tpl.cover()
|
||||
html += '<!--cover-->'
|
||||
}
|
||||
|
||||
html += tpl.main(config)
|
||||
|
|
@ -53,9 +53,9 @@ export default class Renderer {
|
|||
}
|
||||
|
||||
_getPath(url) {
|
||||
const file = this.router.getFile(url)
|
||||
|
||||
return isAbsolutePath(file) ? file : cwd(this.path, `./${file}`)
|
||||
const path = resolve(this.path, url)
|
||||
const file = this.router.getFile(path)
|
||||
return file
|
||||
}
|
||||
|
||||
async render(url) {
|
||||
|
|
@ -77,36 +77,34 @@ export default class Renderer {
|
|||
|
||||
if (loadSidebar) {
|
||||
const name = loadSidebar === true ? '_sidebar.md' : loadSidebar
|
||||
const sidebarFile = this._getPath(resolve(this.path, url, `./${name}`))
|
||||
const sidebarFile = this._getPath(resolvePathname(name, url))
|
||||
this._renderHtml('sidebar', await this._render(sidebarFile, 'sidebar'))
|
||||
}
|
||||
|
||||
if (loadNavbar) {
|
||||
const name = loadNavbar === true ? '_navbar.md' : loadNavbar
|
||||
const navbarFile = this._getPath(resolve(this.path, url, `./${name}`))
|
||||
const navbarFile = this._getPath(resolvePathname(name, url))
|
||||
this._renderHtml('navbar', await this._render(navbarFile, 'navbar'))
|
||||
}
|
||||
|
||||
if (coverpage === true) {
|
||||
coverpage = '_coverpage.md'
|
||||
}
|
||||
if (coverpage) {
|
||||
let path = null
|
||||
if (typeof coverpage === 'string') {
|
||||
let name = null
|
||||
|
||||
if (typeof coverpage === 'string' || coverpage === true) {
|
||||
if (url === 'README.md') {
|
||||
path = coverpage
|
||||
name = coverpage === true ? '_coverpage.md' : coverpage
|
||||
}
|
||||
} else if (Array.isArray(coverpage)) {
|
||||
path = coverpage.indexOf(url) > -1 && '_coverpage.md'
|
||||
name = coverpage.indexOf(url) > -1 && '_coverpage.md'
|
||||
} else {
|
||||
const cover = coverpage[url]
|
||||
path = cover === true ? '_coverpage.md' : cover
|
||||
name = cover === true ? '_coverpage.md' : cover
|
||||
}
|
||||
|
||||
if (path) {
|
||||
const coverFile = this._getPath(resolve(url, `./${path}`))
|
||||
if (name) {
|
||||
const coverFile = this._getPath(resolvePathname(name, url))
|
||||
|
||||
this._renderHtml('cover', await this._render(coverFile), 'cover')
|
||||
this._renderHtml('cover', await this._render(coverFile, 'cover'))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -124,6 +122,7 @@ export default class Renderer {
|
|||
|
||||
async _render(path, type) {
|
||||
let html = await this._loadFile(path)
|
||||
|
||||
const {subMaxLevel, maxLevel} = this.config
|
||||
let tokens
|
||||
|
||||
|
|
@ -142,7 +141,8 @@ export default class Renderer {
|
|||
tokens = await new Promise(r => {
|
||||
prerenderEmbed(
|
||||
{
|
||||
fetch: url => this._loadFile(this._getPath(url)),
|
||||
// Url is absolute path
|
||||
fetch: url => this._loadFile(this._getPath('.' + url)),
|
||||
compiler: this.compiler,
|
||||
raw: html
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import marked from 'marked'
|
||||
import Prism from 'prismjs'
|
||||
import {helper as helperTpl, tree as treeTpl} from './tpl'
|
||||
import {helper as helperTpl, tree as treeTpl, cover as coverTpl} from './tpl'
|
||||
import {genTree} from './gen-tree'
|
||||
import {slugify} from './slugify'
|
||||
import {emojify} from './emojify'
|
||||
|
|
@ -303,19 +303,25 @@ export class Compiler {
|
|||
return `<img src="${url}"data-origin="${href}" alt="${text}"${attrs}>`
|
||||
}
|
||||
origin.list = renderer.list = function (body, ordered, start) {
|
||||
const isTaskList = /<li class="task-list-item">/.test(body.split('class="task-list"')[0])
|
||||
const isTaskList = /<li class="task-list-item">/.test(
|
||||
body.split('class="task-list"')[0]
|
||||
)
|
||||
const isStartReq = start && start > 1
|
||||
const tag = ordered ? 'ol' : 'ul'
|
||||
const tagAttrs = [
|
||||
(isTaskList ? 'class="task-list"' : ''),
|
||||
(isStartReq ? `start="${start}"` : '')
|
||||
].join(' ').trim()
|
||||
isTaskList ? 'class="task-list"' : '',
|
||||
isStartReq ? `start="${start}"` : ''
|
||||
]
|
||||
.join(' ')
|
||||
.trim()
|
||||
|
||||
return `<${tag} ${tagAttrs}>${body}</${tag}>`
|
||||
}
|
||||
origin.listitem = renderer.listitem = function (text) {
|
||||
const isTaskItem = /^(<input.*type="checkbox"[^>]*>)/.test(text)
|
||||
const html = isTaskItem ? `<li class="task-list-item"><label>${text}</label></li>` : `<li>${text}</li>`
|
||||
const html = isTaskItem ?
|
||||
`<li class="task-list-item"><label>${text}</label></li>` :
|
||||
`<li>${text}</li>`
|
||||
|
||||
return html
|
||||
}
|
||||
|
|
@ -375,12 +381,37 @@ export class Compiler {
|
|||
/**
|
||||
* Compile cover page
|
||||
*/
|
||||
cover(text) {
|
||||
const cacheToc = this.toc.slice()
|
||||
const html = this.compile(text)
|
||||
cover(text, isHTML = false) {
|
||||
let html = text
|
||||
if (!isHTML) {
|
||||
const cacheToc = this.toc.slice()
|
||||
html = this.compile(text) || ''
|
||||
this.toc = cacheToc.slice()
|
||||
}
|
||||
|
||||
this.toc = cacheToc.slice()
|
||||
const m = html
|
||||
.trim()
|
||||
.match('<p><img.*?data-origin="(.*?)"[^a]+alt="(.*?)">([^<]*?)</p>$')
|
||||
let style = ''
|
||||
let hasMask = false
|
||||
if (m) {
|
||||
if (m[2] === 'color') {
|
||||
style = `background: ${m[1] + (m[3] || '')}`
|
||||
} else {
|
||||
let path = m[1]
|
||||
hasMask = true
|
||||
if (!isAbsolutePath(m[1])) {
|
||||
path = getPath(this.router.getBasePath(), m[1])
|
||||
}
|
||||
style = `background-image: url(${path}); background-size: cover; background-position: center center;`
|
||||
}
|
||||
html = html.replace(m[0], '')
|
||||
}
|
||||
|
||||
return html
|
||||
return coverTpl({
|
||||
style,
|
||||
hasMask,
|
||||
text: html
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,30 +175,10 @@ export function renderMixin(proto) {
|
|||
}
|
||||
dom.toggleClass(el, 'add', 'show')
|
||||
|
||||
let html = this.coverIsHTML ? text : this.compiler.cover(text)
|
||||
let html = this.compiler.cover(text, this.coverIsHTML)
|
||||
|
||||
const m = html
|
||||
.trim()
|
||||
.match('<p><img.*?data-origin="(.*?)"[^a]+alt="(.*?)">([^<]*?)</p>$')
|
||||
this._renderTo('.cover-placeholder', html, true)
|
||||
|
||||
if (m) {
|
||||
if (m[2] === 'color') {
|
||||
el.style.background = m[1] + (m[3] || '')
|
||||
} else {
|
||||
let path = m[1]
|
||||
|
||||
dom.toggleClass(el, 'add', 'has-mask')
|
||||
if (!isAbsolutePath(m[1])) {
|
||||
path = getPath(this.router.getBasePath(), m[1])
|
||||
}
|
||||
el.style.backgroundImage = `url(${path})`
|
||||
el.style.backgroundSize = 'cover'
|
||||
el.style.backgroundPosition = 'center center'
|
||||
}
|
||||
html = html.replace(m[0], '')
|
||||
}
|
||||
|
||||
this._renderTo('.cover-main', html)
|
||||
sticky()
|
||||
}
|
||||
|
||||
|
|
@ -228,8 +208,9 @@ export function initRender(vm) {
|
|||
if (config.repo) {
|
||||
html += tpl.corner(config.repo)
|
||||
}
|
||||
|
||||
if (config.coverpage) {
|
||||
html += tpl.cover()
|
||||
html += '<div class=cover-placeholder></div>'
|
||||
}
|
||||
|
||||
if (config.logo) {
|
||||
|
|
|
|||
|
|
@ -57,16 +57,19 @@ export function main(config) {
|
|||
/**
|
||||
* Cover Page
|
||||
*/
|
||||
export function cover() {
|
||||
export function cover({style, text, hasMask}) {
|
||||
const SL = ', 100%, 85%'
|
||||
const bgc =
|
||||
'linear-gradient(to left bottom, ' +
|
||||
`hsl(${Math.floor(Math.random() * 255) + SL}) 0%,` +
|
||||
`hsl(${Math.floor(Math.random() * 255) + SL}) 100%)`
|
||||
style =
|
||||
style ||
|
||||
'background: linear-gradient(to left bottom, ' +
|
||||
`hsl(${Math.floor(Math.random() * 255) + SL}) 0%,` +
|
||||
`hsl(${Math.floor(Math.random() * 255) + SL}) 100%)`
|
||||
|
||||
return (
|
||||
`<section class="cover show" style="background: ${bgc}">` +
|
||||
'<div class="cover-main"><!--cover--></div>' +
|
||||
`<section class="cover show ${
|
||||
hasMask ? ' has-mask' : ''
|
||||
}" style="${style}">` +
|
||||
`<div class="cover-main">${text}</div>` +
|
||||
'<div class="mask"></div>' +
|
||||
'</section>'
|
||||
)
|
||||
|
|
@ -84,7 +87,9 @@ export function tree(toc, tpl = '<ul class="app-sub-sidebar">{inner}</ul>') {
|
|||
}
|
||||
let innerHTML = ''
|
||||
toc.forEach(node => {
|
||||
innerHTML += `<li><a class="section-link" href="${node.slug}">${node.title}</a></li>`
|
||||
innerHTML += `<li><a class="section-link" href="${node.slug}">${
|
||||
node.title
|
||||
}</a></li>`
|
||||
if (node.children) {
|
||||
innerHTML += tree(node.children, tpl)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,9 @@ export const isAbsolutePath = cached(path => {
|
|||
export const getParentPath = cached(path => {
|
||||
return /\/$/g.test(path) ?
|
||||
path :
|
||||
(path = path.match(/(\S*\/)[^/]+$/)) ? path[1] : ''
|
||||
(path = path.match(/(\S*\/)[^/]+$/)) ?
|
||||
path[1] :
|
||||
''
|
||||
})
|
||||
|
||||
export const cleanPath = cached(path => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue