[build] 4.9.0

This commit is contained in:
liqingwei 2019-02-19 11:26:53 +08:00
commit d1c72686bb
12 changed files with 74 additions and 22 deletions

View file

@ -1,6 +1,18 @@
(function () {
var INDEXS = {};
var LOCAL_STORAGE = {
EXPIRE_KEY: 'docsify.search.expires',
INDEX_KEY: 'docsify.search.index'
};
function resolveExpireKey(namespace) {
return namespace ? ((LOCAL_STORAGE.EXPIRE_KEY) + "/" + namespace) : LOCAL_STORAGE.EXPIRE_KEY
}
function resolveIndexKey(namespace) {
return namespace ? ((LOCAL_STORAGE.INDEX_KEY) + "/" + namespace) : LOCAL_STORAGE.INDEX_KEY
}
function escapeHtml(string) {
var entityMap = {
'&': '&',
@ -34,9 +46,9 @@ function getAllPaths(router) {
return paths
}
function saveData(maxAge) {
localStorage.setItem('docsify.search.expires', Date.now() + maxAge);
localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS));
function saveData(maxAge, expireKey, indexKey) {
localStorage.setItem(expireKey, Date.now() + maxAge);
localStorage.setItem(indexKey, JSON.stringify(INDEXS));
}
function genIndex(path, content, router, depth) {
@ -154,9 +166,13 @@ function search(query) {
function init$1(config, vm) {
var isAuto = config.paths === 'auto';
var isExpired = localStorage.getItem('docsify.search.expires') < Date.now();
INDEXS = JSON.parse(localStorage.getItem('docsify.search.index'));
var expireKey = resolveExpireKey(config.namespace);
var indexKey = resolveIndexKey(config.namespace);
var isExpired = localStorage.getItem(expireKey) < Date.now();
INDEXS = JSON.parse(localStorage.getItem(indexKey));
if (isExpired) {
INDEXS = {};
@ -177,7 +193,7 @@ function init$1(config, vm) {
.get(vm.router.getFile(path), false, vm.config.requestHeaders)
.then(function (result) {
INDEXS[path] = genIndex(path, result, vm.router, config.depth);
len === ++count && saveData(config.maxAge);
len === ++count && saveData(config.maxAge, expireKey, indexKey);
});
});
}
@ -311,7 +327,8 @@ var CONFIG = {
paths: 'auto',
depth: 2,
maxAge: 86400000, // 1 day
hideOtherSidebarContent: false
hideOtherSidebarContent: false,
namespace: undefined
};
var install = function (hook, vm) {
@ -327,6 +344,7 @@ var install = function (hook, vm) {
CONFIG.noData = opts.noData || CONFIG.noData;
CONFIG.depth = opts.depth || CONFIG.depth;
CONFIG.hideOtherSidebarContent = opts.hideOtherSidebarContent || CONFIG.hideOtherSidebarContent;
CONFIG.namespace = opts.namespace || CONFIG.namespace;
}
var isAuto = CONFIG.paths === 'auto';

File diff suppressed because one or more lines are too long