mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-11-30 19:20:06 +08:00
bump: 3.2
This commit is contained in:
parent
b927a30cc6
commit
61e0aacb43
@ -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) {
|
||||
|
4
lib/docsify.min.js
vendored
4
lib/docsify.min.js
vendored
File diff suppressed because one or more lines are too long
@ -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';
|
||||
|
2
lib/plugins/search.min.js
vendored
2
lib/plugins/search.min.js
vendored
@ -1 +1 @@
|
||||
this.D=this.D||{},function(){"use strict";function e(e){var n={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};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={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};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)}();
|
||||
|
Loading…
Reference in New Issue
Block a user