diff --git a/CHANGELOG.md b/CHANGELOG.md
index f2778c019..52a907610 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,12 @@
+3.2.0 / 2017-02-28
+==================
+
+ * fix(render): Toc rendering error, fixed #106
+ * feat(search): Localization for no data tip, close #103
+ * fix(fetch): load sidebar and navbar for parent path, fixed #100
+ * feat(render) nameLink for each route, fixed #99
+
3.1.2 / 2017-02-27
==================
diff --git a/docs/_coverpage.md b/docs/_coverpage.md
index 292a9523b..0f74e8ffa 100644
--- a/docs/_coverpage.md
+++ b/docs/_coverpage.md
@@ -1,6 +1,6 @@

-# docsify 3.1
+# docsify 3.2
> A magical documentation site generator.
diff --git a/docs/_sidebar.md b/docs/_sidebar.md
index e747a918d..cf254be95 100644
--- a/docs/_sidebar.md
+++ b/docs/_sidebar.md
@@ -17,6 +17,6 @@
- [Helpers](/helpers)
- [Vue compatibility](/vue)
- [CDN](/cdn)
- - [Offline Mode(PWA)new](/pwa)
+ - [Offline Mode(PWA)](/pwa)
- [Changelog](/changelog)
\ No newline at end of file
diff --git a/docs/configuration.md b/docs/configuration.md
index 26e3f0df8..5c997af2f 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -206,7 +206,13 @@ The name of the link.
```js
window.$docsify = {
- nameLink: '/'
+ nameLink: '/',
+
+ // For each route
+ nameLink: {
+ '/zh-cn/': '/zh-cn/',
+ '/': '/'
+ }
}
```
diff --git a/docs/plugins.md b/docs/plugins.md
index 29f434874..3142694cd 100644
--- a/docs/plugins.md
+++ b/docs/plugins.md
@@ -27,6 +27,14 @@ By default, the hyperlink on the current page is recognized and the content is s
placeholder: {
'/zh-cn/': '搜索',
'/': 'Type to search'
+ },
+
+ noData: 'No Results!',
+
+ // Localization
+ noData: {
+ '/zh-cn/': '找不到结果',
+ '/': 'No Results'
}
}
}
diff --git a/docs/zh-cn/_sidebar.md b/docs/zh-cn/_sidebar.md
index 47d970e50..d9376b4a1 100644
--- a/docs/zh-cn/_sidebar.md
+++ b/docs/zh-cn/_sidebar.md
@@ -17,6 +17,6 @@
- [文档助手](zh-cn/helpers)
- [兼容 Vue](zh-cn/vue)
- [CDN](zh-cn/cdn)
- - [离线模式(PWA)new](zh-cn/pwa)
+ - [离线模式(PWA)](zh-cn/pwa)
- [Changelog](zh-cn/changelog)
\ No newline at end of file
diff --git a/docs/zh-cn/configuration.md b/docs/zh-cn/configuration.md
index 28c0af9b3..a474f7d38 100644
--- a/docs/zh-cn/configuration.md
+++ b/docs/zh-cn/configuration.md
@@ -206,7 +206,13 @@ window.$docsify = {
```js
window.$docsify = {
- nameLink: '/'
+ nameLink: '/',
+
+ // 按照路由切换
+ nameLink: {
+ '/zh-cn/': '/zh-cn/',
+ '/': '/'
+ }
}
```
diff --git a/docs/zh-cn/plugins.md b/docs/zh-cn/plugins.md
index aa29eab90..5fa1530a4 100644
--- a/docs/zh-cn/plugins.md
+++ b/docs/zh-cn/plugins.md
@@ -27,6 +27,14 @@
placeholder: {
'/zh-cn/': '搜索',
'/': 'Type to search'
+ },
+
+ noData: 'No Results!',
+
+ // 支持本地化
+ noData: {
+ '/zh-cn/': '找不到结果',
+ '/': 'No Results'
}
}
}
diff --git a/lib/docsify.js b/lib/docsify.js
index 54d5f0666..776c9acc7 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, '');
+ 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) {
diff --git a/lib/docsify.min.js b/lib/docsify.min.js
index c7f1a66cc..1837ca313 100644
--- a/lib/docsify.min.js
+++ b/lib/docsify.min.js
@@ -1,2 +1,2 @@
-!function(){"use strict";function e(e){var t=Object.create(null);return function(n){var r=t[n];return r||(t[n]=e(n))}}function t(e){return"string"==typeof e||"number"==typeof e}function n(){}function r(e){return"function"==typeof e}function i(e){var t=["init","mounted","beforeEach","afterEach","doneEach","ready"];e._hooks={},e._lifecycle={},t.forEach(function(t){var n=e._hooks[t]=[];e._lifecycle[t]=function(e){return n.push(e)}})}function a(e,t,r,i){void 0===i&&(i=n);var a=r,o=e._hooks[t],s=function(e){var t=o[e];if(e>=o.length)i(a);else if("function"==typeof t)if(2===t.length)t(r,function(t){a=t,s(e+1)});else{var n=t(r);a=void 0!==n?n:a,s(e+1)}else s(e+1)};s(0)}function o(e,t){return void 0===t&&(t=!1),"string"==typeof e&&(e=t?s(e):me[e]||s(e)),e}function s(e,t){return t?e.querySelector(t):ve.querySelector(e)}function l(e,t){return[].slice.call(t?e.querySelectorAll(t):ve.querySelectorAll(e))}function u(e,t){return e=ve.createElement(e),t&&(e.innerHTML=t),e}function c(e,t){return e.appendChild(t)}function p(e,t){return e.insertBefore(t,e.children[0])}function h(e,t,n){r(t)?window.addEventListener(e,t):e.addEventListener(t,n)}function d(e,t,n){r(t)?window.removeEventListener(e,t):e.removeEventListener(t,n)}function g(e,t,n){e&&e.classList[n?t:"toggle"](n||t)}function f(e){var t={};return(e=e.trim().replace(/^(\?|#|&)/,""))?(e.split("&").forEach(function(e){var n=e.replace(/\+/g," ").split("=");t[n[0]]=Le(n[1])}),t):t}function m(e){var t=[];for(var n in e)t.push((Se(n)+"="+Se(e[n])).toLowerCase());return t.length?"?"+t.join("&"):""}function v(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];return Te(e.join("/"))}function b(e){var t=window.location.href.indexOf("#");window.location.replace(window.location.href.slice(0,t>=0?t:0)+"#"+e)}function y(){var e=k();return e=Ae(e),"/"===e.charAt(0)?b(e):void b("/"+e)}function k(){var e=window.location.href,t=e.indexOf("#");return t===-1?"":e.slice(t+1)}function w(e){void 0===e&&(e=window.location.href);var t="",n=e.indexOf("?");n>=0&&(t=e.slice(n+1),e=e.slice(0,n));var r=e.indexOf("#");return r&&(e=e.slice(r+1)),{path:e,query:f(t)}}function x(e,t){var n=w(Ae(e));return n.query=ue({},n.query,t),e=n.path+m(n.query),Te("#/"+e)}function _(e){var t=function(){return be.classList.toggle("close")};e=o(e),h(e,"click",t);var n=o(".sidebar");h(n,"click",function(){_e&&t(),setTimeout(function(){return S(n,!0,!0)},0)})}function L(){var e=o("section.cover");if(e){var t=e.getBoundingClientRect().height;window.pageYOffset>=t||e.classList.contains("hidden")?g(be,"add","sticky"):g(be,"remove","sticky")}}function S(e,t,n){e=o(e);var r,i=l(e,"a"),a="#"+k();return i.sort(function(e,t){return t.href.length-e.href.length}).forEach(function(e){var n=e.getAttribute("href"),i=t?e.parentNode:e;0!==a.indexOf(n)||r?g(i,"remove","active"):(r=e,g(i,"add","active"))}),n&&(ve.title=r?r.innerText+" - "+Me:Me),r}function C(){for(var e,t=o(".sidebar"),n=l(".anchor"),r=s(t,".sidebar-nav"),i=s(t,"li.active"),a=be.scrollTop,u=0,c=n.length;ua){e||(e=p);break}e=p}if(e){var h=Oe[e.getAttribute("data-id")];if(h&&h!==i&&(i&&i.classList.remove("active"),h.classList.add("active"),i=h,!qe&&be.classList.contains("sticky"))){var d=t.clientHeight,g=0,f=i.offsetTop+i.clientHeight+40,m=i.offsetTop>=r.scrollTop&&f<=r.scrollTop+d,v=f-g=400?a(n):(Fe[e]=n.response,r(n.response))})},abort:function(e){return 4!==r.readyState&&r.abort()}})}function M(e,t){e.innerHTML=e.innerHTML.replace(/var\(\s*--theme-color.*?\)/g,t)}function O(e){return e?(/\/\//.test(e)||(e="https://github.com/"+e),e=e.replace(/^git\+/,""),''):""}function q(e){var t='';return(_e?t+"":""+t)+''}function P(){var e=", 100%, 85%",t="linear-gradient(to left bottom, hsl("+(Math.floor(255*Math.random())+e)+") 0%,hsl("+(Math.floor(255*Math.random())+e)+") 100%)";return''}function N(e,t){return void 0===t&&(t=""),e&&e.length?(e.forEach(function(e){t+='- '+e.title+"
",e.children&&(t+='
")}),t):""}function F(e,t){return''+t.slice(5).trim()+"
"}function I(e){return""}function z(e,t){return t={exports:{}},e(t,t.exports),t.exports}function H(e,t){var n=[],r={};return e.forEach(function(e){var i=e.level||1,a=i-1;i>t||(r[a]?r[a].children=(r[a].children||[]).concat(e):n.push(e),r[i]=e)}),n}function R(e){if("string"!=typeof e)return"";var t=e.toLowerCase().trim().replace(/<[^>\d]+>/g,"").replace(Be,"").replace(/\s/g,"-").replace(/-+/g,"-").replace(/^(\d)/,"_$1"),n=We[t];return n=We.hasOwnProperty(t)?n+1:0,We[t]=n,n&&(t=t+"-"+n),t}function W(e,t){return'
'}function B(e){return e.replace(/<(pre|template|code)[^>]*?>[\s\S]+?<\/(pre|template|code)>/g,function(e){return e.replace(/:/g,"__colon__")}).replace(/:(\w+?):/gi,window.emojify||W).replace(/__colon__/g,":")}function D(e,t){var n="";if(e)n=Ye(e),n=n.match(/]*>([\s\S]+)<\/ul>/g)[0];else{var r=H(Ve,t);n=N(r,"")}return n}function U(e,t){if(e){Ve[0]&&1===Ve[0].level&&Ve.shift();var n=Ze[Ge]||H(Ve,t);e.parentNode.innerHTML+=N(n,'