mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
bump: 2.1.0
This commit is contained in:
parent
0ca1ece188
commit
dc35b051d3
@ -6,6 +6,9 @@
|
||||
<script src="//unpkg.com/docsify/lib/plugins/search.js"></script>
|
||||
```
|
||||
|
||||
### Bug fixes
|
||||
- fix sidebar style
|
||||
|
||||
## 2.0.3
|
||||
### Bug fixes
|
||||
- fix: rendering emojis
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||

|
||||
|
||||
# docsify <small>2.0.3</small>
|
||||
# docsify <small>2.1.0</small>
|
||||
|
||||
> A magical documentation site generator.
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
data-max-level="4"
|
||||
data-coverpage
|
||||
data-name="docsify"></script>
|
||||
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
|
||||
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
|
||||
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
|
||||
</html>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
var Docsify = (function () {
|
||||
var D = (function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@ -97,7 +97,7 @@ function getRoute () {
|
||||
var loc = window.location;
|
||||
if (cacheHash === loc.hash && !isNil(cacheRoute$1)) { return cacheRoute$1 }
|
||||
|
||||
var route = loc.hash.match(/^#\/([^#]+)/);
|
||||
var route = loc.hash.replace(/%23/g, '#').match(/^#\/([^#]+)/);
|
||||
|
||||
if (route && route.length === 2) {
|
||||
route = route[1];
|
||||
@ -175,6 +175,20 @@ function emojify (text) {
|
||||
.replace(/__colon__/g, ':')
|
||||
}
|
||||
|
||||
|
||||
|
||||
var utils = Object.freeze({
|
||||
load: load,
|
||||
genTree: genTree,
|
||||
camel2kebab: camel2kebab,
|
||||
isNil: isNil,
|
||||
getRoute: getRoute,
|
||||
isMobile: isMobile,
|
||||
slugify: slugify,
|
||||
merge: merge,
|
||||
emojify: emojify
|
||||
});
|
||||
|
||||
/**
|
||||
* Active sidebar when scroll
|
||||
* @link https://buble.surge.sh/
|
||||
@ -184,7 +198,7 @@ function scrollActiveSidebar () {
|
||||
|
||||
var hoveredOverSidebar = false;
|
||||
var anchors = document.querySelectorAll('.anchor');
|
||||
var sidebar = document.querySelector('aside.sidebar');
|
||||
var sidebar = document.querySelector('.sidebar');
|
||||
var sidebarHeight = sidebar.clientHeight;
|
||||
|
||||
var nav = {};
|
||||
@ -299,7 +313,7 @@ function bindToggle (dom) {
|
||||
dom.addEventListener('click', function () { return body.classList.toggle('close'); });
|
||||
|
||||
if (isMobile()) {
|
||||
var sidebar = document.querySelector('aside.sidebar');
|
||||
var sidebar = document.querySelector('.sidebar');
|
||||
sidebar.addEventListener('click', function () {
|
||||
body.classList.toggle('close');
|
||||
setTimeout(function () { return activeLink(sidebar, true); }, 0);
|
||||
@ -2449,7 +2463,7 @@ function corner (data) {
|
||||
* Render main content
|
||||
*/
|
||||
function main () {
|
||||
var aside = (toggle()) + "<aside class=\"sidebar\"></aside>";
|
||||
var aside = (toggle()) + "<aside class=\"sidebar\"><div class=\"sidebar-nav\"></div></aside>";
|
||||
|
||||
return (isMobile() ? (aside + "<main>") : ("<main>" + aside)) +
|
||||
"<section class=\"content\">\n <article class=\"markdown-section\"></article>\n </section>\n </main>"
|
||||
@ -2499,7 +2513,7 @@ function theme (color) {
|
||||
}
|
||||
|
||||
function replaceVar (block) {
|
||||
block.innerHTML = block.innerHTML.replace(/var\(\s*--theme-color.*?\)/g, __docsify__.themeColor);
|
||||
block.innerHTML = block.innerHTML.replace(/var\(\s*--theme-color.*?\)/g, $docsify.themeColor);
|
||||
}
|
||||
|
||||
function cssVars () {
|
||||
@ -2565,7 +2579,7 @@ function init () {
|
||||
};
|
||||
renderer.link = function (href, title, text) {
|
||||
if (!/:/.test(href)) {
|
||||
href = ("#/" + href).replace(/\/\//g, '/');
|
||||
href = ("#/" + href).replace(/\/+/g, '/');
|
||||
}
|
||||
|
||||
return ("<a href=\"" + href + "\" title=\"" + (title || '') + "\">" + text + "</a>")
|
||||
@ -2579,16 +2593,22 @@ function init () {
|
||||
return ("<p>" + text + "</p>")
|
||||
};
|
||||
|
||||
if (typeof __docsify__.markdown === 'function') {
|
||||
if (typeof $docsify.markdown === 'function') {
|
||||
markdown.setOptions({ renderer: renderer });
|
||||
markdown = __docsify__.markdown.call(this, markdown);
|
||||
markdown = $docsify.markdown.call(this, markdown);
|
||||
} else {
|
||||
markdown.setOptions(merge({ renderer: renderer }, __docsify__.markdown));
|
||||
markdown.setOptions(merge({ renderer: renderer }, $docsify.markdown));
|
||||
}
|
||||
|
||||
var md = markdown;
|
||||
|
||||
markdown = function (text) { return emojify(md(text)); };
|
||||
|
||||
window.Docsify.utils.marked = function (text) {
|
||||
var result = markdown(text);
|
||||
toc = [];
|
||||
return result
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2596,27 +2616,35 @@ function init () {
|
||||
*/
|
||||
function renderApp (dom, replace) {
|
||||
var nav = document.querySelector('nav') || document.createElement('nav');
|
||||
var body = document.body;
|
||||
var head = document.head;
|
||||
|
||||
if (!__docsify__.repo) { nav.classList.add('no-badge'); }
|
||||
if (!$docsify.repo) { nav.classList.add('no-badge'); }
|
||||
|
||||
dom[replace ? 'outerHTML' : 'innerHTML'] = corner(__docsify__.repo) +
|
||||
(__docsify__.coverpage ? cover() : '') +
|
||||
dom[replace ? 'outerHTML' : 'innerHTML'] = corner($docsify.repo) +
|
||||
($docsify.coverpage ? cover() : '') +
|
||||
main();
|
||||
document.body.insertBefore(nav, document.body.children[0]);
|
||||
body.insertBefore(nav, body.children[0]);
|
||||
|
||||
// theme color
|
||||
if (__docsify__.themeColor) {
|
||||
document.head.innerHTML += theme(__docsify__.themeColor);
|
||||
if ($docsify.themeColor) {
|
||||
head.innerHTML += theme($docsify.themeColor);
|
||||
cssVars();
|
||||
}
|
||||
|
||||
// render name
|
||||
if ($docsify.name) {
|
||||
var aside = document.querySelector('.sidebar');
|
||||
aside.innerHTML = "<h1><a href=\"" + ($docsify.nameLink) + "\">" + ($docsify.name) + "</a></h1>" + aside.innerHTML;
|
||||
}
|
||||
|
||||
// bind toggle
|
||||
bindToggle('button.sidebar-toggle');
|
||||
// bind sticky effect
|
||||
if (__docsify__.coverpage) {
|
||||
if ($docsify.coverpage) {
|
||||
!isMobile() && window.addEventListener('scroll', sticky);
|
||||
} else {
|
||||
document.body.classList.add('sticky');
|
||||
body.classList.add('sticky');
|
||||
}
|
||||
}
|
||||
|
||||
@ -2625,7 +2653,7 @@ function renderApp (dom, replace) {
|
||||
*/
|
||||
function renderArticle (content) {
|
||||
renderTo('article', content ? markdown(content) : 'not found');
|
||||
if (!__docsify__.loadSidebar) { renderSidebar(); }
|
||||
if (!$docsify.loadSidebar) { renderSidebar(); }
|
||||
|
||||
if (content && typeof Vue !== 'undefined') {
|
||||
CACHE.vm && CACHE.vm.$destroy();
|
||||
@ -2642,7 +2670,7 @@ function renderArticle (content) {
|
||||
: new Vue({ el: 'main' }); // eslint-disable-line
|
||||
CACHE.vm && CACHE.vm.$nextTick(function (_) { return scrollActiveSidebar(); });
|
||||
}
|
||||
if (__docsify__.auto2top) { setTimeout(function () { return scroll2Top(__docsify__.auto2top); }, 0); }
|
||||
if ($docsify.auto2top) { setTimeout(function () { return scroll2Top($docsify.auto2top); }, 0); }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2667,12 +2695,11 @@ function renderSidebar (content) {
|
||||
// find url tag
|
||||
html = html.match(/<ul[^>]*>([\s\S]+)<\/ul>/g)[0];
|
||||
} else {
|
||||
html = tree(genTree(toc, __docsify__.maxLevel), '<ul>');
|
||||
html = tree(genTree(toc, $docsify.maxLevel), '<ul>');
|
||||
}
|
||||
|
||||
html = (__docsify__.name ? ("<h1><a href=\"" + (__docsify__.nameLink) + "\">" + (__docsify__.name) + "</a></h1>") : '') + html;
|
||||
renderTo('aside.sidebar', html);
|
||||
var target = activeLink('aside.sidebar', true);
|
||||
renderTo('.sidebar-nav', html);
|
||||
var target = activeLink('.sidebar-nav', true);
|
||||
if (target) { renderSubSidebar(target); }
|
||||
toc = [];
|
||||
|
||||
@ -2680,8 +2707,8 @@ function renderSidebar (content) {
|
||||
}
|
||||
|
||||
function renderSubSidebar (target) {
|
||||
if (!__docsify__.subMaxLevel) { return }
|
||||
target.parentNode.innerHTML += tree(genTree(toc, __docsify__.subMaxLevel), '<ul>');
|
||||
if (!$docsify.subMaxLevel) { return }
|
||||
target.parentNode.innerHTML += tree(genTree(toc, $docsify.subMaxLevel), '<ul>');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2790,10 +2817,14 @@ if (script) {
|
||||
}
|
||||
|
||||
// utils
|
||||
window.__docsify__ = OPTIONS;
|
||||
window.$docsify = OPTIONS;
|
||||
window.Docsify = {
|
||||
installed: true,
|
||||
utils: merge({}, utils)
|
||||
};
|
||||
|
||||
// load options
|
||||
init(OPTIONS);
|
||||
init();
|
||||
|
||||
var cacheRoute = null;
|
||||
var cacheXhr = null;
|
||||
@ -2811,6 +2842,7 @@ var mainRender = function (cb) {
|
||||
}
|
||||
|
||||
var page;
|
||||
|
||||
if (!route) {
|
||||
page = OPTIONS.homepage || 'README.md';
|
||||
} else if (/\/$/.test(route)) {
|
||||
@ -2855,7 +2887,8 @@ var Docsify = function () {
|
||||
var main = function () {
|
||||
mainRender(function (_) {
|
||||
scrollIntoView();
|
||||
activeLink('nav');
|
||||
activeLink('nav')
|
||||
;[].concat(window.$docsify.plugins).forEach(function (fn) { return fn && fn(); });
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
4
lib/docsify.min.js
vendored
4
lib/docsify.min.js
vendored
File diff suppressed because one or more lines are too long
284
lib/plugins/search.js
Normal file
284
lib/plugins/search.js
Normal file
@ -0,0 +1,284 @@
|
||||
this.D = this.D || {};
|
||||
this.D.Search = (function () {
|
||||
'use strict';
|
||||
|
||||
var INDEXS = {};
|
||||
var CONFIG = {
|
||||
placeholder: 'Type to search',
|
||||
paths: 'auto',
|
||||
maxAge: 86400000 // 1 day
|
||||
};
|
||||
|
||||
var isObj = function (obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object Object]'
|
||||
};
|
||||
|
||||
var escapeHtml = function (string) {
|
||||
var entityMap = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
'/': '/'
|
||||
};
|
||||
|
||||
return String(string).replace(/[&<>"'\/]/g, function (s) { return entityMap[s]; })
|
||||
};
|
||||
|
||||
/**
|
||||
* find all filepath from A tag
|
||||
*/
|
||||
var getAllPaths = function () {
|
||||
var paths = [];[].slice.call(document.querySelectorAll('a'))
|
||||
.map(function (node) {
|
||||
var href = node.href;
|
||||
if (/#\/[^#]*?$/.test(href)) {
|
||||
var path = href.replace(/^[^#]+#/, '');
|
||||
|
||||
if (paths.indexOf(path) <= 0) { paths.push(path); }
|
||||
}
|
||||
});
|
||||
|
||||
return paths
|
||||
};
|
||||
|
||||
/**
|
||||
* return file path
|
||||
*/
|
||||
var genFilePath = function (path) {
|
||||
var basePath = window.$docsify.basePath;
|
||||
var filePath = /\/$/.test(path) ? (path + "README.md") : (path + ".md");
|
||||
|
||||
filePath = basePath + filePath;
|
||||
|
||||
return filePath.replace(/\/+/g, '/')
|
||||
};
|
||||
|
||||
/**
|
||||
* generate index
|
||||
*/
|
||||
var genIndex = function (path, content) {
|
||||
if ( content === void 0 ) content = '';
|
||||
|
||||
INDEXS[path] = { slug: '', title: '', body: '' };
|
||||
var slug;
|
||||
|
||||
content
|
||||
// remove PRE and TEMPLATE tag
|
||||
.replace(/<template[^>]*?>[\s\S]+?<\/template>/g, '')
|
||||
// find all html tag
|
||||
.replace(/<(\w+)([^>]*?)>([\s\S]+?)<\//g, function (match, tag, attr, html) {
|
||||
// remove all html tag
|
||||
var text = html.replace(/<[^>]+>/g, '');
|
||||
|
||||
// tag is headline
|
||||
if (/^h\d$/.test(tag)) {
|
||||
// <h1 id="xxx"></h1>
|
||||
var id = attr.match(/id="(\S+)"/)[1];
|
||||
|
||||
slug = ("#/" + path + "#" + id).replace(/\/+/, '/');
|
||||
INDEXS[slug] = { slug: slug, title: text, body: '' };
|
||||
} else {
|
||||
// other html tag
|
||||
if (!INDEXS[slug]) {
|
||||
INDEXS[slug] = {};
|
||||
} else {
|
||||
if (INDEXS[slug].body && INDEXS[slug].body.length) {
|
||||
INDEXS[slug].body += '\n' + text;
|
||||
} else {
|
||||
INDEXS[slug].body = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* component
|
||||
*/
|
||||
var SearchComponent = function SearchComponent () {
|
||||
if (this.rendered) { return }
|
||||
|
||||
this.style();
|
||||
|
||||
var el = document.createElement('div');
|
||||
var aside = document.querySelector('aside');
|
||||
|
||||
el.classList.add('search');
|
||||
aside.insertBefore(el, aside.children[0]);
|
||||
this.render(el);
|
||||
this.rendered = true;
|
||||
this.bindEvent();
|
||||
};
|
||||
|
||||
SearchComponent.prototype.style = 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 }\n ";
|
||||
var style = document.createElement('style');
|
||||
|
||||
style.innerHTML = code;
|
||||
document.head.appendChild(style);
|
||||
};
|
||||
|
||||
SearchComponent.prototype.render = function render (dom) {
|
||||
dom.innerHTML = "<input type=\"search\" placeholder=\"" + (CONFIG.placeholder) + "\" /><div class=\"results-panel\"></div>";
|
||||
};
|
||||
|
||||
SearchComponent.prototype.bindEvent = function bindEvent () {
|
||||
var this$1 = this;
|
||||
|
||||
var input = document.querySelector('.search input');
|
||||
var panel = document.querySelector('.results-panel');
|
||||
|
||||
input.addEventListener('input', function (e) {
|
||||
var target = e.target;
|
||||
|
||||
if (target.value.trim() !== '') {
|
||||
var matchingPosts = this$1.search(target.value);
|
||||
var html = '';
|
||||
|
||||
matchingPosts.forEach(function (post, index) {
|
||||
html += "\n <div class=\"matching-post\">\n <h2><a href=\"" + (post.url) + "\">" + (post.title) + "</a></h2>\n <p>" + (post.content) + "</p>\n </div>\n ";
|
||||
});
|
||||
if (panel.classList.contains('results-panel')) {
|
||||
panel.classList.add('show');
|
||||
panel.innerHTML = html || '<p class="empty">No Results!</p>';
|
||||
}
|
||||
} else {
|
||||
if (panel.classList.contains('results-panel')) {
|
||||
panel.classList.remove('show');
|
||||
panel.innerHTML = '';
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// From [weex website] https://weex-project.io/js/common.js
|
||||
SearchComponent.prototype.search = function search (keywords) {
|
||||
var matchingResults = [];
|
||||
var data = Object.keys(INDEXS).map(function (key) { return INDEXS[key]; });
|
||||
|
||||
keywords = keywords.trim().split(/[\s\-\,\\/]+/);
|
||||
|
||||
var loop = function ( i ) {
|
||||
var post = data[i];
|
||||
var isMatch = false;
|
||||
var resultStr = '';
|
||||
var postTitle = post.title && post.title.trim();
|
||||
var postContent = post.body && post.body.trim();
|
||||
var postUrl = post.slug || '';
|
||||
|
||||
if (postTitle !== '' && postContent !== '') {
|
||||
keywords.forEach(function (keyword, i) {
|
||||
var regEx = new RegExp(keyword, 'gi');
|
||||
var indexTitle = -1;
|
||||
var indexContent = -1;
|
||||
|
||||
indexTitle = postTitle.search(regEx);
|
||||
indexContent = postContent.search(regEx);
|
||||
|
||||
if (indexTitle < 0 && indexContent < 0) {
|
||||
isMatch = false;
|
||||
} else {
|
||||
isMatch = true;
|
||||
if (indexContent < 0) { indexContent = 0; }
|
||||
|
||||
var start = 0;
|
||||
var end = 0;
|
||||
|
||||
start = indexContent < 11 ? 0 : indexContent - 10;
|
||||
end = start === 0 ? 70 : indexContent + keyword.length + 60;
|
||||
|
||||
if (end > postContent.length) { end = postContent.length; }
|
||||
|
||||
var matchContent = '...' +
|
||||
postContent
|
||||
.substring(start, end)
|
||||
.replace(regEx, ("<em class=\"search-keyword\">" + keyword + "</em>")) +
|
||||
'...';
|
||||
|
||||
resultStr += matchContent;
|
||||
}
|
||||
});
|
||||
|
||||
if (isMatch) {
|
||||
var matchingPost = {
|
||||
title: escapeHtml(postTitle),
|
||||
content: resultStr,
|
||||
url: postUrl
|
||||
};
|
||||
|
||||
matchingResults.push(matchingPost);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (var i = 0; i < data.length; i++) loop( i );
|
||||
|
||||
return matchingResults
|
||||
};
|
||||
|
||||
var searchPlugin = function () {
|
||||
var isAuto = CONFIG.paths === 'auto';
|
||||
var isExpired = localStorage.getItem('docsify.search.expires') < Date.now();
|
||||
|
||||
INDEXS = JSON.parse(localStorage.getItem('docsify.search.index'));
|
||||
|
||||
if (isExpired) {
|
||||
INDEXS = {};
|
||||
} else if (!isAuto) {
|
||||
return
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
var paths = isAuto ? getAllPaths() : CONFIG.paths;
|
||||
var len = paths.length;
|
||||
var ref = window.Docsify.utils;
|
||||
var load = ref.load;
|
||||
var marked = ref.marked;
|
||||
var slugify = ref.slugify;
|
||||
var done = function () {
|
||||
localStorage.setItem('docsify.search.expires', Date.now() + CONFIG.maxAge);
|
||||
localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS));
|
||||
};
|
||||
|
||||
paths.forEach(function (path) {
|
||||
if (INDEXS[path]) { return count++ }
|
||||
|
||||
load(genFilePath(path)).then(function (content) {
|
||||
genIndex(path, marked(content));
|
||||
slugify.clear();
|
||||
count++;
|
||||
|
||||
if (len === count) { done(); }
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var install = function () {
|
||||
if (!window.Docsify || !window.Docsify.installed) {
|
||||
console.error('[Docsify] Please load docsify.js first.');
|
||||
return
|
||||
}
|
||||
|
||||
window.$docsify.plugins = [].concat(window.$docsify.plugins, searchPlugin);
|
||||
|
||||
var userConfig = window.$docsify.search;
|
||||
var isNil = window.Docsify.utils.isNil;
|
||||
|
||||
if (Array.isArray(userConfig)) {
|
||||
CONFIG.paths = userConfig;
|
||||
} else if (isObj(userConfig)) {
|
||||
CONFIG.paths = Array.isArray(userConfig.paths) ? userConfig.paths : 'auto';
|
||||
CONFIG.maxAge = isNil(userConfig.maxAge) ? CONFIG.maxAge : userConfig.maxAge;
|
||||
CONFIG.placeholder = userConfig.placeholder || CONFIG.placeholder;
|
||||
}
|
||||
|
||||
new SearchComponent();
|
||||
};
|
||||
|
||||
var search = install();
|
||||
|
||||
return search;
|
||||
|
||||
}());
|
||||
1
lib/plugins/search.min.js
vendored
Normal file
1
lib/plugins/search.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
this.D=this.D||{},this.D.Search=function(){"use strict";var e={},n={placeholder:"Type to search",paths:"auto",maxAge:864e5},t=function(e){return"[object Object]"===Object.prototype.toString.call(e)},r=function(e){var n={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};return String(e).replace(/[&<>"'\/]/g,function(e){return n[e]})},i=function(){var e=[];return[].slice.call(document.querySelectorAll("a")).map(function(n){var t=n.href;if(/#\/[^#]*?$/.test(t)){var r=t.replace(/^[^#]+#/,"");e.indexOf(r)<=0&&e.push(r)}}),e},a=function(e){var n=window.$docsify.basePath,t=/\/$/.test(e)?e+"README.md":e+".md";return t=n+t,t.replace(/\/+/g,"/")},o=function(n,t){void 0===t&&(t=""),e[n]={slug:"",title:"",body:""};var r;t.replace(/<template[^>]*?>[\s\S]+?<\/template>/g,"").replace(/<(\w+)([^>]*?)>([\s\S]+?)<\//g,function(t,i,a,o){var s=o.replace(/<[^>]+>/g,"");if(/^h\d$/.test(i)){var c=a.match(/id="(\S+)"/)[1];r=("#/"+n+"#"+c).replace(/\/+/,"/"),e[r]={slug:r,title:s,body:""}}else e[r]?e[r].body&&e[r].body.length?e[r].body+="\n"+s:e[r].body=s:e[r]={}})},s=function(){if(!this.rendered){this.style();var e=document.createElement("div"),n=document.querySelector("aside");e.classList.add("search"),n.insertBefore(e,n.children[0]),this.render(e),this.rendered=!0,this.bindEvent()}};s.prototype.style=function e(){var n="\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 ",e=document.createElement("style");e.innerHTML=n,document.head.appendChild(e)},s.prototype.render=function(e){e.innerHTML='<input type="search" placeholder="'+n.placeholder+'" /><div class="results-panel"></div>'},s.prototype.bindEvent=function(){var e=this,n=document.querySelector(".search input"),t=document.querySelector(".results-panel");n.addEventListener("input",function(n){var r=n.target;if(""!==r.value.trim()){var i=e.search(r.value),a="";i.forEach(function(e,n){a+='\n <div class="matching-post">\n <h2><a href="'+e.url+'">'+e.title+"</a></h2>\n <p>"+e.content+"</p>\n </div>\n "}),t.classList.contains("results-panel")&&(t.classList.add("show"),t.innerHTML=a||'<p class="empty">No Results!</p>')}else t.classList.contains("results-panel")&&(t.classList.remove("show"),t.innerHTML="")})},s.prototype.search=function(n){var t=[],i=Object.keys(e).map(function(n){return e[n]});n=n.trim().split(/[\s\-\,\\\/]+/);for(var a=function(e){var a=i[e],o=!1,s="",c=a.title&&a.title.trim(),l=a.body&&a.body.trim(),d=a.slug||"";if(""!==c&&""!==l&&(n.forEach(function(e,n){var t=new RegExp(e,"gi"),r=-1,i=-1;if(r=c.search(t),i=l.search(t),r<0&&i<0)o=!1;else{o=!0,i<0&&(i=0);var a=0,d=0;a=i<11?0:i-10,d=0===a?70:i+e.length+60,d>l.length&&(d=l.length);var p="..."+l.substring(a,d).replace(t,'<em class="search-keyword">'+e+"</em>")+"...";s+=p}}),o)){var p={title:r(c),content:s,url:d};t.push(p)}},o=0;o<i.length;o++)a(o);return t};var c=function(){var t="auto"===n.paths,r=localStorage.getItem("docsify.search.expires")<Date.now();if(e=JSON.parse(localStorage.getItem("docsify.search.index")),r)e={};else if(!t)return;var s=0,c=t?i():n.paths,l=c.length,d=window.Docsify.utils,p=d.load,h=d.marked,u=d.slugify,f=function(){localStorage.setItem("docsify.search.expires",Date.now()+n.maxAge),localStorage.setItem("docsify.search.index",JSON.stringify(e))};c.forEach(function(n){return e[n]?s++:void p(a(n)).then(function(e){o(n,h(e)),u.clear(),s++,l===s&&f()})})},l=function(){if(!window.Docsify||!window.Docsify.installed)return void console.error("[Docsify] Please load docsify.js first.");window.$docsify.plugins=[].concat(window.$docsify.plugins,c);var e=window.$docsify.search,r=window.Docsify.utils.isNil;Array.isArray(e)?n.paths=e:t(e)&&(n.paths=Array.isArray(e.paths)?e.paths:"auto",n.maxAge=r(e.maxAge)?n.maxAge:e.maxAge,n.placeholder=e.placeholder||n.placeholder),new s},d=l();return d}();
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user