diff --git a/lib/docsify.js b/lib/docsify.js index 54d5f06..776c9ac 100644 --- a/lib/docsify.js +++ b/lib/docsify.js @@ -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) { '' + ''); @@ -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(/]*>([\s\S]+)<\/ul>/g)[0]; } else { - var tree$$1 = genTree(toc, level); + var tree$$1 = cacheTree[currentPath] || genTree(toc, level); html = tree(tree$$1, '