bump: 3.0.0 close #78

This commit is contained in:
qingwei.li 2017-02-19 14:40:16 +08:00
commit 74ce0bf588
10 changed files with 1358 additions and 957 deletions

File diff suppressed because it is too large Load diff

4
lib/docsify.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,9 +1,8 @@
this.D = this.D || {}; this.D = this.D || {};
this.D.GA = (function () { (function () {
'use strict'; 'use strict';
// From https://github.com/egoist/vue-ga/blob/master/src/index.js // From https://github.com/egoist/vue-ga/blob/master/src/index.js
function appendScript () { function appendScript () {
var script = document.createElement('script'); var script = document.createElement('script');
script.async = true; script.async = true;
@ -28,23 +27,15 @@ function collect () {
window.ga('send', 'pageview'); window.ga('send', 'pageview');
} }
var install = function () { var install = function (hook) {
if (install.installed) { return }
install.installed = true;
if (!window.$docsify.ga) { if (!window.$docsify.ga) {
console.error('[Docsify] ga is required.'); console.error('[Docsify] ga is required.');
return return
} }
window.$docsify.plugins = [].concat(function (hook) { hook.beforeEach(collect);
hook.init(collect);
hook.beforeEach(collect);
}, window.$docsify.plugins);
}; };
var ga = install(); window.$docsify.plugins = [].concat(install, window.$docsify.plugins);
return ga;
}()); }());

View file

@ -1 +1 @@
this.D=this.D||{},this.D.GA=function(){"use strict";function i(){var i=document.createElement("script");i.async=!0,i.src="https://www.google-analytics.com/analytics.js",document.body.appendChild(i)}function n(n){window.ga||(i(),window.ga=window.ga||function(){(window.ga.q=window.ga.q||[]).push(arguments)},window.ga.l=Number(new Date),window.ga("create",n,"auto"))}function o(){n(window.$docsify.ga),window.ga("set","page",location.href),window.ga("send","pageview")}var t=function(){if(!t.installed)return t.installed=!0,window.$docsify.ga?void(window.$docsify.plugins=[].concat(function(i){i.init(o),i.beforeEach(o)},window.$docsify.plugins)):void console.error("[Docsify] ga is required.")},a=t();return a}(); this.D=this.D||{},function(){"use strict";function n(){var n=document.createElement("script");n.async=!0,n.src="https://www.google-analytics.com/analytics.js",document.body.appendChild(n)}function o(o){window.ga||(n(),window.ga=window.ga||function(){(window.ga.q=window.ga.q||[]).push(arguments)},window.ga.l=Number(new Date),window.ga("create",o,"auto"))}function i(){o(window.$docsify.ga),window.ga("set","page",location.href),window.ga("send","pageview")}var w=function(n){return window.$docsify.ga?void n.beforeEach(i):void console.error("[Docsify] ga is required.")};window.$docsify.plugins=[].concat(w,window.$docsify.plugins)}();

View file

@ -1,166 +1,82 @@
this.D = this.D || {}; this.D = this.D || {};
this.D.Search = (function () { (function () {
'use strict'; 'use strict';
var INDEXS = {}; var INDEXS = {};
var CONFIG = { var helper;
placeholder: 'Type to search',
paths: 'auto',
maxAge: 86400000 // 1 day
};
var isObj = function (obj) { function escapeHtml (string) {
return Object.prototype.toString.call(obj) === '[object Object]'
};
var escapeHtml = function (string) {
var entityMap = { var entityMap = {
'&': '&', '&': '&',
'<': '&lt;', '<': '&lt;',
'>': '&gt;', '>': '&gt;',
'"': '&quot;', '"': '&quot;',
"'": '&#39;', '\'': '&#39;',
'/': '&#x2F;' '/': '&#x2F;'
}; };
return String(string).replace(/[&<>"'\/]/g, function (s) { return entityMap[s]; }) return String(string).replace(/[&<>"'\/]/g, function (s) { return entityMap[s]; })
}; }
/** function getAllPaths () {
* find all filepath from A tag var paths = [];
*/
var getAllPaths = function () { helper.dom.findAll('a')
var paths = [];[].slice.call(document.querySelectorAll('a'))
.map(function (node) { .map(function (node) {
var href = node.href; var href = node.href;
if (/#\/[^#]*?$/.test(href)) { var originHref = node.getAttribute('href');
var path = href.replace(/^[^#]+#/, ''); var path = helper.route.parse(href).path;
if (paths.indexOf(path) <= 0) { paths.push(path); } if (path &&
paths.indexOf(path) === -1 &&
!helper.route.isAbsolutePath(originHref)) {
paths.push(path);
} }
}); });
return paths return paths
}; }
/** function saveData (maxAge) {
* return file path localStorage.setItem('docsify.search.expires', Date.now() + maxAge);
*/ localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS));
var genFilePath = function (path, basePath) { }
if ( basePath === void 0 ) basePath = window.$docsify.basePath;
var filePath = /\/$/.test(path) ? (path + "README.md") : (path + ".md"); function genIndex (path, content) {
filePath = basePath + filePath;
return filePath.replace(/\/+/g, '/')
};
/**
* generate index
*/
var genIndex = function (path, content) {
if ( content === void 0 ) content = ''; if ( content === void 0 ) content = '';
INDEXS[path] = { slug: '', title: '', body: '' }; var tokens = window.marked.lexer(content);
var toURL = Docsify.route.toURL;
var index = {};
var slug; var slug;
content tokens.forEach(function (token) {
// remove PRE and TEMPLATE tag if (token.type === 'heading' && token.depth <= 2) {
.replace(/<template[^>]*?>[\s\S]+?<\/template>/g, '') slug = toURL(path, { id: token.text });
// find all html tag index[slug] = { slug: slug, title: token.text, body: '' };
.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 {
if (!slug) { return }
// 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 search = document.querySelector('.search');
var input = search.querySelector('.search input');
var panel = search.querySelector('.results-panel');
search.addEventListener('click', function (e) { return e.target.tagName !== 'A' && e.stopPropagation(); });
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 { } else {
if (panel.classList.contains('results-panel')) { if (!slug) { return }
panel.classList.remove('show'); if (!index[slug]) {
panel.innerHTML = ''; index[slug] = { slug: slug, title: '', body: '' };
} else {
if (index[slug].body) {
index[slug].body += '\n' + (token.text || '');
} else {
index[slug].body = token.text;
}
} }
} }
}); });
};
// From [weex website] https://weex-project.io/js/common.js return index
SearchComponent.prototype.search = function search (keywords) { }
function search (keywords) {
var matchingResults = []; var matchingResults = [];
var data = Object.keys(INDEXS).map(function (key) { return INDEXS[key]; }); var data = [];
Object.keys(INDEXS).forEach(function (key) {
data = data.concat(Object.keys(INDEXS[key]).map(function (page) { return INDEXS[key][page]; }));
});
keywords = keywords.trim().split(/[\s\-\\\/]+/); keywords = keywords.trim().split(/[\s\-\\\/]+/);
@ -196,7 +112,7 @@ SearchComponent.prototype.search = function search (keywords) {
if (end > postContent.length) { end = postContent.length; } if (end > postContent.length) { end = postContent.length; }
var matchContent = '...' + var matchContent = '...' +
postContent escapeHtml(postContent)
.substring(start, end) .substring(start, end)
.replace(regEx, ("<em class=\"search-keyword\">" + keyword + "</em>")) + .replace(regEx, ("<em class=\"search-keyword\">" + keyword + "</em>")) +
'...'; '...';
@ -217,13 +133,15 @@ SearchComponent.prototype.search = function search (keywords) {
} }
}; };
for (var i = 0; i < data.length; i++) loop( i ); for (var i = 0; i < data.length; i++) loop( i );
return matchingResults return matchingResults
}; }
var searchPlugin = function () { function init$1 (config, vm) {
var isAuto = CONFIG.paths === 'auto'; helper = Docsify;
var isAuto = config.paths === 'auto';
var isExpired = localStorage.getItem('docsify.search.expires') < Date.now(); var isExpired = localStorage.getItem('docsify.search.expires') < Date.now();
INDEXS = JSON.parse(localStorage.getItem('docsify.search.index')); INDEXS = JSON.parse(localStorage.getItem('docsify.search.index'));
@ -234,68 +152,123 @@ var searchPlugin = function () {
return return
} }
var count = 0; var paths = isAuto ? getAllPaths() : config.paths;
var paths = isAuto ? getAllPaths() : CONFIG.paths;
var len = paths.length; var len = paths.length;
var ref = window.Docsify.utils; var count = 0;
var load = ref.load;
var marked = ref.marked;
var slugify = ref.slugify;
var alias = window.$docsify.alias;
var done = function () {
localStorage.setItem('docsify.search.expires', Date.now() + CONFIG.maxAge);
localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS));
};
paths.forEach(function (path) { paths.forEach(function (path) {
if (INDEXS[path]) { return count++ } if (INDEXS[path]) { return count++ }
var route;
// replace route helper
if (alias && alias[path]) { .get(vm.$getFile(path))
route = genFilePath(alias[path] || path, ''); .then(function (result) {
} else { INDEXS[path] = genIndex(path, result);
route = genFilePath(path); len === ++count && saveData(config.maxAge);
});
});
}
var dom;
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}";
var style = dom.create('style', code);
dom.appendTo(dom.head, style);
}
function tpl (opts) {
var html =
"<input type=\"search\" />" +
'<div class="results-panel"></div>' +
'</div>';
var el = dom.create('div', html);
var aside = dom.find('aside');
dom.toggleClass(el, 'search');
dom.before(aside, el);
}
function bindEvents () {
var $search = dom.find('div.search');
var $input = dom.find($search, 'input');
var $panel = dom.find($search, '.results-panel');
// Prevent to Fold sidebar
dom.on($search, 'click',
function (e) { return e.target.tagName !== 'A' && e.stopPropagation(); });
dom.on($input, 'input', function (e) {
var value = e.target.value.trim();
if (!value) {
$panel.classList.remove('show');
$panel.innerHTML = '';
return
} }
var matchs = search(value);
load(route).then(function (content) { var html = '';
genIndex(path, marked(content));
slugify.clear();
count++;
if (len === count) { done(); } matchs.forEach(function (post) {
html += "<div class=\"matching-post\">\n <h2><a href=\"" + (post.url) + "\">" + (post.title) + "</a></h2>\n <p>" + (post.content) + "</p>\n</div>";
}); });
$panel.classList.add('show');
$panel.innerHTML = html || '<p class="empty">No Results!</p>';
});
}
function updatePlaceholder (text, path) {
var $input = dom.getNode('.search input[type="search"]');
if (typeof text === 'string') {
$input.placeholder = text;
} else {
var match = Object.keys(text).find(function (key) { return path.indexOf(key) > -1; });
$input.placeholder = text[match];
}
}
function init$$1 (opts) {
dom = Docsify.dom;
style();
tpl(opts);
bindEvents();
}
function update (opts, vm) {
updatePlaceholder(opts.placeholder, vm.route.path);
}
var CONFIG = {
placeholder: 'Type to search',
paths: 'auto',
maxAge: 86400000 // 1 day
};
var install = function (hook, vm) {
var util = Docsify.util;
var opts = vm.config.search || CONFIG;
if (Array.isArray(opts)) {
CONFIG.paths = opts;
} else if (typeof opts === 'object') {
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;
}
var isAuto = CONFIG.paths === 'auto';
hook.mounted(function (_) {
init$$1(CONFIG);
!isAuto && init$1(CONFIG, vm);
});
hook.doneEach(function (_) {
update(CONFIG, vm);
isAuto && init$1(CONFIG, vm);
}); });
}; };
var install = function () { window.$docsify.plugins = [].concat(install, window.$docsify.plugins);
if (install.installed) { return }
install.installed = true;
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;
}
window.$docsify.plugins = [].concat(function (hook) {
var isAuto = CONFIG.paths === 'auto';
hook.ready(function () {
new SearchComponent();
!isAuto && searchPlugin();
});
isAuto && hook.doneEach(searchPlugin);
}, window.$docsify.plugins);
};
var search = install();
return search;
}()); }());

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long