bump: 3.2
This commit is contained in:
parent
b927a30cc6
commit
61e0aacb43
4 changed files with 60 additions and 22 deletions
|
|
@ -300,8 +300,12 @@ var isAbsolutePath = cached(function (path) {
|
|||
return /(:|(\/{2}))/.test(path)
|
||||
});
|
||||
|
||||
var getRoot = cached(function (path) {
|
||||
return /\/$/g.test(path) ? path : path.match(/(\S*\/)[^\/]+$/)[1]
|
||||
var getParentPath = cached(function (path) {
|
||||
return /\/$/g.test(path)
|
||||
? path
|
||||
: (path = path.match(/(\S*\/)[^\/]+$/))
|
||||
? path[1]
|
||||
: ''
|
||||
});
|
||||
|
||||
var cleanPath = cached(function (path) {
|
||||
|
|
@ -393,7 +397,7 @@ var route = Object.freeze({
|
|||
getBasePath: getBasePath,
|
||||
getPath: getPath,
|
||||
isAbsolutePath: isAbsolutePath,
|
||||
getRoot: getRoot,
|
||||
getParentPath: getParentPath,
|
||||
cleanPath: cleanPath
|
||||
});
|
||||
|
||||
|
|
@ -711,7 +715,7 @@ 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>');
|
||||
|
|
@ -2966,7 +2970,6 @@ markdown.init = function (config, base) {
|
|||
if ( base === void 0 ) base = window.location.pathname;
|
||||
|
||||
contentBase = getBasePath(base);
|
||||
currentPath = parse().path;
|
||||
|
||||
if (isFn(config)) {
|
||||
markdownCompiler = config(marked, renderer);
|
||||
|
|
@ -3041,8 +3044,9 @@ function sidebar (text, level) {
|
|||
html = markdown(text);
|
||||
html = html.match(/<ul[^>]*>([\s\S]+)<\/ul>/g)[0];
|
||||
} else {
|
||||
var tree$$1 = genTree(toc, level);
|
||||
var tree$$1 = cacheTree[currentPath] || genTree(toc, level);
|
||||
html = tree(tree$$1, '<ul>');
|
||||
cacheTree[currentPath] = tree$$1;
|
||||
}
|
||||
|
||||
return html
|
||||
|
|
@ -3121,6 +3125,22 @@ function renderMain (html) {
|
|||
}
|
||||
}
|
||||
|
||||
function renderNameLink (vm) {
|
||||
var el = getNode('.app-name-link');
|
||||
var nameLink = vm.config.nameLink;
|
||||
var path = vm.route.path;
|
||||
|
||||
if (!el) { return }
|
||||
|
||||
if (isPrimitive(vm.config.nameLink)) {
|
||||
el.setAttribute('href', nameLink);
|
||||
} else if (typeof nameLink === 'object') {
|
||||
var match = Object.keys(nameLink).find(function (key) { return path.indexOf(key) > -1; });
|
||||
|
||||
el.setAttribute('href', nameLink[match]);
|
||||
}
|
||||
}
|
||||
|
||||
function renderMixin (proto) {
|
||||
proto._renderTo = function (el, content, replace) {
|
||||
var node = getNode(el);
|
||||
|
|
@ -3136,7 +3156,7 @@ function renderMixin (proto) {
|
|||
|
||||
this._renderTo('.sidebar-nav', sidebar(text, maxLevel));
|
||||
var active = getAndActive('.sidebar-nav', true, true);
|
||||
loadSidebar && subSidebar(active, subMaxLevel);
|
||||
subSidebar(loadSidebar ? active : '', subMaxLevel);
|
||||
// bind event
|
||||
this.activeLink = active;
|
||||
scrollActiveSidebar();
|
||||
|
|
@ -3200,6 +3220,8 @@ function renderMixin (proto) {
|
|||
|
||||
proto._updateRender = function () {
|
||||
markdown.update();
|
||||
// render name link
|
||||
renderNameLink(this);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -3278,6 +3300,7 @@ var lastRoute = {};
|
|||
function initRoute (vm) {
|
||||
normalize();
|
||||
lastRoute = vm.route = parse();
|
||||
vm._updateRender();
|
||||
|
||||
on('hashchange', function (_) {
|
||||
normalize();
|
||||
|
|
@ -3312,6 +3335,16 @@ function initEvent (vm) {
|
|||
}
|
||||
}
|
||||
|
||||
function loadNested (path, file, next, vm, first) {
|
||||
path = first ? path : path.replace(/\/$/, '');
|
||||
path = getParentPath(path);
|
||||
|
||||
if (!path) { return }
|
||||
|
||||
get(vm.$getFile(path + file))
|
||||
.then(next, function (_) { return loadNested(path, file, next, vm); });
|
||||
}
|
||||
|
||||
function fetchMixin (proto) {
|
||||
var last;
|
||||
proto._fetch = function (cb) {
|
||||
|
|
@ -3323,7 +3356,6 @@ function fetchMixin (proto) {
|
|||
var ref$1 = this.config;
|
||||
var loadNavbar = ref$1.loadNavbar;
|
||||
var loadSidebar = ref$1.loadSidebar;
|
||||
var root = getRoot(path);
|
||||
|
||||
// Abort last request
|
||||
last && last.abort && last.abort();
|
||||
|
|
@ -3341,20 +3373,13 @@ function fetchMixin (proto) {
|
|||
var fn = function (result) { this$1._renderSidebar(result); cb(); };
|
||||
|
||||
// Load sidebar
|
||||
get(this$1.$getFile(root + loadSidebar))
|
||||
// fallback root navbar when fail
|
||||
.then(fn, function (_) { return get(loadSidebar).then(fn); });
|
||||
loadNested(path, loadSidebar, fn, this$1, true);
|
||||
},
|
||||
function (_) { return this$1._renderMain(null); });
|
||||
|
||||
// Load nav
|
||||
loadNavbar &&
|
||||
get(this.$getFile(root + loadNavbar))
|
||||
.then(
|
||||
function (text) { return this$1._renderNav(text); },
|
||||
// fallback root navbar when fail
|
||||
function (_) { return get(loadNavbar).then(function (text) { return this$1._renderNav(text); }); }
|
||||
);
|
||||
loadNested(path, loadNavbar, function (text) { return this$1._renderNav(text); }, this, true);
|
||||
};
|
||||
|
||||
proto._fetchCover = function () {
|
||||
|
|
@ -3362,7 +3387,7 @@ function fetchMixin (proto) {
|
|||
|
||||
var ref = this.config;
|
||||
var coverpage = ref.coverpage;
|
||||
var root = getRoot(this.route.path);
|
||||
var root = getParentPath(this.route.path);
|
||||
var path = this.$getFile(root + coverpage);
|
||||
|
||||
if (this.route.path !== '/' || !coverpage) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue