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