bump 2.3.0

This commit is contained in:
qingwei.li 2017-02-13 22:51:31 +08:00
commit ec8b17bd43
11 changed files with 183 additions and 66 deletions

View file

@ -46,8 +46,9 @@ var getAllPaths = function () {
/**
* return file path
*/
var genFilePath = function (path) {
var basePath = window.$docsify.basePath;
var genFilePath = function (path, basePath) {
if ( basePath === void 0 ) basePath = window.$docsify.basePath;
var filePath = /\/$/.test(path) ? (path + "README.md") : (path + ".md");
filePath = basePath + filePath;
@ -240,6 +241,7 @@ var searchPlugin = function () {
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));
@ -247,8 +249,16 @@ var searchPlugin = function () {
paths.forEach(function (path) {
if (INDEXS[path]) { return count++ }
var route;
load(genFilePath(path)).then(function (content) {
// replace route
if (alias && alias[path]) {
route = genFilePath(alias[path] || path, '');
} else {
route = genFilePath(path);
}
load(route).then(function (content) {
genIndex(path, marked(content));
slugify.clear();
count++;
@ -259,12 +269,8 @@ var searchPlugin = function () {
};
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);
if (install.installed) { return }
install.installed = true;
var userConfig = window.$docsify.search;
var isNil = window.Docsify.utils.isNil;
@ -277,7 +283,15 @@ var install = function () {
CONFIG.placeholder = userConfig.placeholder || CONFIG.placeholder;
}
new SearchComponent();
window.$docsify.plugins = [].concat(function (hook) {
var isAuto = CONFIG.paths === 'auto';
hook.ready(function () {
new SearchComponent();
!isAuto && searchPlugin();
});
isAuto && hook.beforeEach(searchPlugin);
}, window.$docsify.plugins);
};
var search = install();