Compare commits

...
9 Commits
21 changed files with 160 additions and 47 deletions
+8
View File
@@ -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
==================
+1 -1
View File
@@ -1,6 +1,6 @@
![logo](_media/icon.svg)
# docsify <small>3.1</small>
# docsify <small>3.2</small>
> A magical documentation site generator.
+1 -1
View File
@@ -17,6 +17,6 @@
- [Helpers](/helpers)
- [Vue compatibility](/vue)
- [CDN](/cdn)
- [Offline Mode(PWA)<sup style="color: #F44336;">new</sup>](/pwa)
- [Offline Mode(PWA)](/pwa)
- [Changelog](/changelog)
+7 -1
View File
@@ -206,7 +206,13 @@ The name of the link.
```js
window.$docsify = {
nameLink: '/'
nameLink: '/',
// For each route
nameLink: {
'/zh-cn/': '/zh-cn/',
'/': '/'
}
}
```
+8
View File
@@ -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'
}
}
}
+1 -1
View File
@@ -17,6 +17,6 @@
- [文档助手](zh-cn/helpers)
- [兼容 Vue](zh-cn/vue)
- [CDN](zh-cn/cdn)
- [离线模式(PWA)<sup style="color: #F44336;">new</sup>](zh-cn/pwa)
- [离线模式(PWA)](zh-cn/pwa)
- [Changelog](zh-cn/changelog)
+7 -1
View File
@@ -206,7 +206,13 @@ window.$docsify = {
```js
window.$docsify = {
nameLink: '/'
nameLink: '/',
// 按照路由切换
nameLink: {
'/zh-cn/': '/zh-cn/',
'/': '/'
}
}
```
+8
View File
@@ -27,6 +27,14 @@
placeholder: {
'/zh-cn/': '搜索',
'/': 'Type to search'
},
noData: 'No Results!',
// 支持本地化
noData: {
'/zh-cn/': '找不到结果',
'/': 'No Results'
}
}
}
+43 -18
View File
@@ -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) {
+2 -2
View File
File diff suppressed because one or more lines are too long
+14 -1
View File
@@ -170,6 +170,7 @@ function init$1 (config, vm) {
}
var dom;
var NO_DATA_TEXT = '';
function style () {
var code = "\n.sidebar {\n padding-top: 0;\n}\n\n.search {\n margin-bottom: 20px;\n padding: 6px;\n border-bottom: 1px solid #eee;\n}\n\n.search .results-panel {\n display: none;\n}\n\n.search .results-panel.show {\n display: block;\n}\n\n.search input {\n outline: none;\n border: none;\n width: 100%;\n padding: 7px;\n line-height: 22px;\n font-size: 14px;\n}\n\n.search h2 {\n font-size: 17px;\n margin: 10px 0;\n}\n\n.search a {\n text-decoration: none;\n color: inherit;\n}\n\n.search .matching-post {\n border-bottom: 1px solid #eee;\n}\n\n.search .matching-post:last-child {\n border-bottom: 0;\n}\n\n.search p {\n font-size: 14px;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n}\n\n.search p.empty {\n text-align: center;\n}";
@@ -207,7 +208,7 @@ function bindEvents () {
});
$panel.classList.add('show');
$panel.innerHTML = html || '<p class="empty">No Results!</p>';
$panel.innerHTML = html || ("<p class=\"empty\">" + NO_DATA_TEXT + "</p>");
};
var timeId;
@@ -231,6 +232,15 @@ function updatePlaceholder (text, path) {
}
}
function updateNoData (text, path) {
if (typeof text === 'string') {
NO_DATA_TEXT = text;
} else {
var match = Object.keys(text).find(function (key) { return path.indexOf(key) > -1; });
NO_DATA_TEXT = text[match];
}
}
function init$$1 (opts) {
dom = Docsify.dom;
style();
@@ -240,10 +250,12 @@ function init$$1 (opts) {
function update (opts, vm) {
updatePlaceholder(opts.placeholder, vm.route.path);
updateNoData(opts.noData, vm.route.path);
}
var CONFIG = {
placeholder: 'Type to search',
noData: 'No Results!',
paths: 'auto',
maxAge: 86400000 // 1 day
};
@@ -258,6 +270,7 @@ var install = function (hook, vm) {
CONFIG.paths = Array.isArray(opts.paths) ? opts.paths : 'auto';
CONFIG.maxAge = util.isPrimitive(opts.maxAge) ? opts.maxAge : CONFIG.maxAge;
CONFIG.placeholder = opts.placeholder || CONFIG.placeholder;
CONFIG.noData = opts.noData || CONFIG.noData;
}
var isAuto = CONFIG.paths === 'auto';
+1 -1
View File
@@ -1 +1 @@
this.D=this.D||{},function(){"use strict";function e(e){var n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};return String(e).replace(/[&<>"'\/]/g,function(e){return n[e]})}function n(){var e=[];return d.dom.findAll("a:not([data-nosearch])").map(function(n){var t=n.href,i=n.getAttribute("href"),r=d.route.parse(t).path;r&&e.indexOf(r)===-1&&!d.route.isAbsolutePath(i)&&e.push(r)}),e}function t(e){localStorage.setItem("docsify.search.expires",Date.now()+e),localStorage.setItem("docsify.search.index",JSON.stringify(f))}function i(e,n){void 0===n&&(n="");var t,i=window.marked.lexer(n),r=window.Docsify.slugify,o=Docsify.route.toURL,a={};return i.forEach(function(n){if("heading"===n.type&&n.depth<=2)t=o(e,{id:r(n.text)}),a[t]={slug:t,title:n.text,body:""};else{if(!t)return;a[t]?a[t].body?a[t].body+="\n"+(n.text||""):a[t].body=n.text:a[t]={slug:t,title:"",body:""}}}),r.clear(),a}function r(n){var t=[],i=[];Object.keys(f).forEach(function(e){i=i.concat(Object.keys(f[e]).map(function(n){return f[e][n]}))}),n=n.trim().split(/[\s\-\\\\/]+/);for(var r=function(r){var o=i[r],a=!1,s="",c=o.title&&o.title.trim(),l=o.body&&o.body.trim(),u=o.slug||"";if(c&&l&&(n.forEach(function(n,t){var i=new RegExp(n,"gi"),r=-1,o=-1;if(r=c&&c.search(i),o=l&&l.search(i),r<0&&o<0)a=!1;else{a=!0,o<0&&(o=0);var u=0,p=0;u=o<11?0:o-10,p=0===u?70:o+n.length+60,p>l.length&&(p=l.length);var d="..."+e(l).substring(u,p).replace(i,'<em class="search-keyword">'+n+"</em>")+"...";s+=d}}),a)){var p={title:e(c),content:s,url:u};t.push(p)}},o=0;o<i.length;o++)r(o);return t}function o(e,r){d=Docsify;var o="auto"===e.paths,a=localStorage.getItem("docsify.search.expires")<Date.now();if(f=JSON.parse(localStorage.getItem("docsify.search.index")),a)f={};else if(!o)return;var s=o?n():e.paths,c=s.length,l=0;s.forEach(function(n){return f[n]?l++:void d.get(r.$getFile(n)).then(function(r){f[n]=i(n,r),c===++l&&t(e.maxAge)})})}function a(){var e="\n.sidebar {\n padding-top: 0;\n}\n\n.search {\n margin-bottom: 20px;\n padding: 6px;\n border-bottom: 1px solid #eee;\n}\n\n.search .results-panel {\n display: none;\n}\n\n.search .results-panel.show {\n display: block;\n}\n\n.search input {\n outline: none;\n border: none;\n width: 100%;\n padding: 7px;\n line-height: 22px;\n font-size: 14px;\n}\n\n.search h2 {\n font-size: 17px;\n margin: 10px 0;\n}\n\n.search a {\n text-decoration: none;\n color: inherit;\n}\n\n.search .matching-post {\n border-bottom: 1px solid #eee;\n}\n\n.search .matching-post:last-child {\n border-bottom: 0;\n}\n\n.search p {\n font-size: 14px;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n}\n\n.search p.empty {\n text-align: center;\n}",n=h.create("style",e);h.appendTo(h.head,n)}function s(e){var n='<input type="search" /><div class="results-panel"></div></div>',t=h.create("div",n),i=h.find("aside");h.toggleClass(t,"search"),h.before(i,t)}function c(){var e,n=h.find("div.search"),t=h.find(n,"input"),i=h.find(n,".results-panel"),o=function(e){if(!e)return i.classList.remove("show"),void(i.innerHTML="");var n=r(e),t="";n.forEach(function(e){t+='<div class="matching-post">\n <h2><a href="'+e.url+'">'+e.title+"</a></h2>\n <p>"+e.content+"</p>\n</div>"}),i.classList.add("show"),i.innerHTML=t||'<p class="empty">No Results!</p>'};h.on(n,"click",function(e){return"A"!==e.target.tagName&&e.stopPropagation()}),h.on(t,"input",function(n){clearTimeout(e),e=setTimeout(function(e){return o(n.target.value.trim())},100)})}function l(e,n){var t=h.getNode('.search input[type="search"]');if("string"==typeof e)t.placeholder=e;else{var i=Object.keys(e).find(function(e){return n.indexOf(e)>-1});t.placeholder=e[i]}}function u(e){h=Docsify.dom,a(),s(e),c()}function p(e,n){l(e.placeholder,n.route.path)}var d,h,f={},g={placeholder:"Type to search",paths:"auto",maxAge:864e5},m=function(e,n){var t=Docsify.util,i=n.config.search||g;Array.isArray(i)?g.paths=i:"object"==typeof i&&(g.paths=Array.isArray(i.paths)?i.paths:"auto",g.maxAge=t.isPrimitive(i.maxAge)?i.maxAge:g.maxAge,g.placeholder=i.placeholder||g.placeholder);var r="auto"===g.paths;e.mounted(function(e){u(g),!r&&o(g,n)}),e.doneEach(function(e){p(g,n),r&&o(g,n)})};window.$docsify.plugins=[].concat(m,window.$docsify.plugins)}();
this.D=this.D||{},function(){"use strict";function e(e){var n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};return String(e).replace(/[&<>"'\/]/g,function(e){return n[e]})}function n(){var e=[];return d.dom.findAll("a:not([data-nosearch])").map(function(n){var t=n.href,o=n.getAttribute("href"),a=d.route.parse(t).path;a&&e.indexOf(a)===-1&&!d.route.isAbsolutePath(o)&&e.push(a)}),e}function t(e){localStorage.setItem("docsify.search.expires",Date.now()+e),localStorage.setItem("docsify.search.index",JSON.stringify(g))}function o(e,n){void 0===n&&(n="");var t,o=window.marked.lexer(n),a=window.Docsify.slugify,i=Docsify.route.toURL,r={};return o.forEach(function(n){if("heading"===n.type&&n.depth<=2)t=i(e,{id:a(n.text)}),r[t]={slug:t,title:n.text,body:""};else{if(!t)return;r[t]?r[t].body?r[t].body+="\n"+(n.text||""):r[t].body=n.text:r[t]={slug:t,title:"",body:""}}}),a.clear(),r}function a(n){var t=[],o=[];Object.keys(g).forEach(function(e){o=o.concat(Object.keys(g[e]).map(function(n){return g[e][n]}))}),n=n.trim().split(/[\s\-\\\\/]+/);for(var a=function(a){var i=o[a],r=!1,s="",c=i.title&&i.title.trim(),l=i.body&&i.body.trim(),u=i.slug||"";if(c&&l&&(n.forEach(function(n,t){var o=new RegExp(n,"gi"),a=-1,i=-1;if(a=c&&c.search(o),i=l&&l.search(o),a<0&&i<0)r=!1;else{r=!0,i<0&&(i=0);var u=0,f=0;u=i<11?0:i-10,f=0===u?70:i+n.length+60,f>l.length&&(f=l.length);var p="..."+e(l).substring(u,f).replace(o,'<em class="search-keyword">'+n+"</em>")+"...";s+=p}}),r)){var f={title:e(c),content:s,url:u};t.push(f)}},i=0;i<o.length;i++)a(i);return t}function i(e,a){d=Docsify;var i="auto"===e.paths,r=localStorage.getItem("docsify.search.expires")<Date.now();if(g=JSON.parse(localStorage.getItem("docsify.search.index")),r)g={};else if(!i)return;var s=i?n():e.paths,c=s.length,l=0;s.forEach(function(n){return g[n]?l++:void d.get(a.$getFile(n)).then(function(a){g[n]=o(n,a),c===++l&&t(e.maxAge)})})}function r(){var e="\n.sidebar {\n padding-top: 0;\n}\n\n.search {\n margin-bottom: 20px;\n padding: 6px;\n border-bottom: 1px solid #eee;\n}\n\n.search .results-panel {\n display: none;\n}\n\n.search .results-panel.show {\n display: block;\n}\n\n.search input {\n outline: none;\n border: none;\n width: 100%;\n padding: 7px;\n line-height: 22px;\n font-size: 14px;\n}\n\n.search h2 {\n font-size: 17px;\n margin: 10px 0;\n}\n\n.search a {\n text-decoration: none;\n color: inherit;\n}\n\n.search .matching-post {\n border-bottom: 1px solid #eee;\n}\n\n.search .matching-post:last-child {\n border-bottom: 0;\n}\n\n.search p {\n font-size: 14px;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n}\n\n.search p.empty {\n text-align: center;\n}",n=h.create("style",e);h.appendTo(h.head,n)}function s(e){var n='<input type="search" /><div class="results-panel"></div></div>',t=h.create("div",n),o=h.find("aside");h.toggleClass(t,"search"),h.before(o,t)}function c(){var e,n=h.find("div.search"),t=h.find(n,"input"),o=h.find(n,".results-panel"),i=function(e){if(!e)return o.classList.remove("show"),void(o.innerHTML="");var n=a(e),t="";n.forEach(function(e){t+='<div class="matching-post">\n <h2><a href="'+e.url+'">'+e.title+"</a></h2>\n <p>"+e.content+"</p>\n</div>"}),o.classList.add("show"),o.innerHTML=t||'<p class="empty">'+y+"</p>"};h.on(n,"click",function(e){return"A"!==e.target.tagName&&e.stopPropagation()}),h.on(t,"input",function(n){clearTimeout(e),e=setTimeout(function(e){return i(n.target.value.trim())},100)})}function l(e,n){var t=h.getNode('.search input[type="search"]');if("string"==typeof e)t.placeholder=e;else{var o=Object.keys(e).find(function(e){return n.indexOf(e)>-1});t.placeholder=e[o]}}function u(e,n){if("string"==typeof e)y=e;else{var t=Object.keys(e).find(function(e){return n.indexOf(e)>-1});y=e[t]}}function f(e){h=Docsify.dom,r(),s(e),c()}function p(e,n){l(e.placeholder,n.route.path),u(e.noData,n.route.path)}var d,h,g={},y="",m={placeholder:"Type to search",noData:"No Results!",paths:"auto",maxAge:864e5},v=function(e,n){var t=Docsify.util,o=n.config.search||m;Array.isArray(o)?m.paths=o:"object"==typeof o&&(m.paths=Array.isArray(o.paths)?o.paths:"auto",m.maxAge=t.isPrimitive(o.maxAge)?o.maxAge:m.maxAge,m.placeholder=o.placeholder||m.placeholder,m.noData=o.noData||m.noData);var a="auto"===m.paths;e.mounted(function(e){f(m),!a&&i(m,n)}),e.doneEach(function(e){p(m,n),a&&i(m,n)})};window.$docsify.plugins=[].concat(v,window.$docsify.plugins)}();
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "docsify",
"version": "3.1.2",
"version": "3.2.0",
"description": "A magical documentation generator.",
"main": "lib/docsify.js",
"files": [
+14 -12
View File
@@ -1,14 +1,23 @@
import { get } from './ajax'
import { callHook } from '../init/lifecycle'
import { getRoot } from '../route/util'
import { getParentPath } from '../route/util'
import { noop } from '../util/core'
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, _ => loadNested(path, file, next, vm))
}
export function fetchMixin (proto) {
let last
proto._fetch = function (cb = noop) {
const { path } = this.route
const { loadNavbar, loadSidebar } = this.config
const root = getRoot(path)
// Abort last request
last && last.abort && last.abort()
@@ -26,25 +35,18 @@ export function fetchMixin (proto) {
const fn = result => { this._renderSidebar(result); cb() }
// Load sidebar
get(this.$getFile(root + loadSidebar))
// fallback root navbar when fail
.then(fn, _ => get(loadSidebar).then(fn))
loadNested(path, loadSidebar, fn, this, true)
},
_ => this._renderMain(null))
// Load nav
loadNavbar &&
get(this.$getFile(root + loadNavbar))
.then(
text => this._renderNav(text),
// fallback root navbar when fail
_ => get(loadNavbar).then(text => this._renderNav(text))
)
loadNested(path, loadNavbar, text => this._renderNav(text), this, true)
}
proto._fetchCover = function () {
const { coverpage } = this.config
const root = getRoot(this.route.path)
const root = getParentPath(this.route.path)
const path = this.$getFile(root + coverpage)
if (this.route.path !== '/' || !coverpage) {
+2 -2
View File
@@ -34,7 +34,6 @@ markdown.renderer = renderer
markdown.init = function (config = {}, base = window.location.pathname) {
contentBase = getBasePath(base)
currentPath = parse().path
if (isFn(config)) {
markdownCompiler = config(marked, renderer)
@@ -107,8 +106,9 @@ export function sidebar (text, level) {
html = markdown(text)
html = html.match(/<ul[^>]*>([\s\S]+)<\/ul>/g)[0]
} else {
const tree = genTree(toc, level)
const tree = cacheTree[currentPath] || genTree(toc, level)
html = treeTpl(tree, '<ul>')
cacheTree[currentPath] = tree
}
return html
+20 -1
View File
@@ -6,6 +6,7 @@ import * as tpl from './tpl'
import { markdown, sidebar, subSidebar, cover } from './compiler'
import { callHook } from '../init/lifecycle'
import { getBasePath, getPath, isAbsolutePath } from '../route/util'
import { isPrimitive } from '../util/core'
function executeScript () {
const script = dom.findAll('.markdown-section>script')
@@ -47,6 +48,22 @@ function renderMain (html) {
}
}
function renderNameLink (vm) {
const el = dom.getNode('.app-name-link')
const nameLink = vm.config.nameLink
const path = vm.route.path
if (!el) return
if (isPrimitive(vm.config.nameLink)) {
el.setAttribute('href', nameLink)
} else if (typeof nameLink === 'object') {
const match = Object.keys(nameLink).find(key => path.indexOf(key) > -1)
el.setAttribute('href', nameLink[match])
}
}
export function renderMixin (proto) {
proto._renderTo = function (el, content, replace) {
const node = dom.getNode(el)
@@ -58,7 +75,7 @@ export function renderMixin (proto) {
this._renderTo('.sidebar-nav', sidebar(text, maxLevel))
const active = getAndActive('.sidebar-nav', true, true)
loadSidebar && subSidebar(active, subMaxLevel)
subSidebar(loadSidebar ? active : '', subMaxLevel)
// bind event
this.activeLink = active
scrollActiveSidebar()
@@ -120,6 +137,8 @@ export function renderMixin (proto) {
proto._updateRender = function () {
markdown.update()
// render name link
renderNameLink(this)
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ export 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>')
+1
View File
@@ -34,6 +34,7 @@ let lastRoute = {}
export function initRoute (vm) {
normalize()
lastRoute = vm.route = parse()
vm._updateRender()
on('hashchange', _ => {
normalize()
+6 -2
View File
@@ -45,8 +45,12 @@ export const isAbsolutePath = cached(path => {
return /(:|(\/{2}))/.test(path)
})
export const getRoot = cached(path => {
return /\/$/g.test(path) ? path : path.match(/(\S*\/)[^\/]+$/)[1]
export const getParentPath = cached(path => {
return /\/$/g.test(path)
? path
: (path = path.match(/(\S*\/)[^\/]+$/))
? path[1]
: ''
})
export const cleanPath = cached(path => {
+12 -1
View File
@@ -1,6 +1,7 @@
import { search } from './search'
let dom
let NO_DATA_TEXT = ''
function style () {
const code = `
@@ -98,7 +99,7 @@ function bindEvents () {
})
$panel.classList.add('show')
$panel.innerHTML = html || '<p class="empty">No Results!</p>'
$panel.innerHTML = html || `<p class="empty">${NO_DATA_TEXT}</p>`
}
let timeId
@@ -122,6 +123,15 @@ function updatePlaceholder (text, path) {
}
}
function updateNoData (text, path) {
if (typeof text === 'string') {
NO_DATA_TEXT = text
} else {
const match = Object.keys(text).find(key => path.indexOf(key) > -1)
NO_DATA_TEXT = text[match]
}
}
export function init (opts) {
dom = Docsify.dom
style()
@@ -131,5 +141,6 @@ export function init (opts) {
export function update (opts, vm) {
updatePlaceholder(opts.placeholder, vm.route.path)
updateNoData(opts.noData, vm.route.path)
}
+2
View File
@@ -3,6 +3,7 @@ import { init as initSearch } from './search'
const CONFIG = {
placeholder: 'Type to search',
noData: 'No Results!',
paths: 'auto',
maxAge: 86400000 // 1 day
}
@@ -17,6 +18,7 @@ const install = function (hook, vm) {
CONFIG.paths = Array.isArray(opts.paths) ? opts.paths : 'auto'
CONFIG.maxAge = util.isPrimitive(opts.maxAge) ? opts.maxAge : CONFIG.maxAge
CONFIG.placeholder = opts.placeholder || CONFIG.placeholder
CONFIG.noData = opts.noData || CONFIG.noData
}
const isAuto = CONFIG.paths === 'auto'