Skip to content

Commit

Permalink
[build] 4.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Feb 19, 2019
1 parent 8cd786c commit d1c7268
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo](_media/icon.svg)

# docsify <small>4.8.6</small>
# docsify <small>4.9.0</small>

> A magical documentation site generator.
Expand Down
45 changes: 39 additions & 6 deletions lib/docsify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3335,7 +3335,7 @@ function getAndRemoveConfig(str) {
str = str
.replace(/^'/, '')
.replace(/'$/, '')
.replace(/:([\w-]+)=?([\w-]+)?/g, function (m, key, value) {
.replace(/(?:^|\s):([\w-]+)=?([\w-]+)?/g, function (m, key, value) {
config[key] = (value && value.replace(/&quot;/g, '')) || true;
return ''
})
Expand Down Expand Up @@ -3483,6 +3483,7 @@ Compiler.prototype.compileEmbed = function compileEmbed (href, title) {
embed = compileMedia[type].call(this, href, title);
embed.type = type;
}
embed.fragment = config.fragment;

return embed
}
Expand Down Expand Up @@ -3633,6 +3634,23 @@ Compiler.prototype._initRenderer = function _initRenderer () {

return ("<img src=\"" + url + "\"data-origin=\"" + href + "\" alt=\"" + text + "\"" + attrs + ">")
};
origin.list = renderer.list = function (body, ordered, start) {
var isTaskList = /<li class="task-list-item">/.test(body.split('class="task-list"')[0]);
var isStartReq = start && start > 1;
var tag = ordered ? 'ol' : 'ul';
var tagAttrs = [
(isTaskList ? 'class="task-list"' : ''),
(isStartReq ? ("start=\"" + start + "\"") : '')
].join(' ').trim();

return ("<" + tag + " " + tagAttrs + ">" + body + "</" + tag + ">")
};
origin.listitem = renderer.listitem = function (text) {
var isTaskItem = /^(<input.*type="checkbox"[^>]*>)/.test(text);
var html = isTaskItem ? ("<li class=\"task-list-item\"><label>" + text + "</label></li>") : ("<li>" + text + "</li>");

return html
};

renderer.origin = origin;

Expand Down Expand Up @@ -3708,6 +3726,9 @@ function btn(el) {
var toggle = function (_) { return body.classList.toggle('close'); };

el = getNode(el);
if (el == null) {
return
}
on(el, 'click', function (e) {
e.stopPropagation();
toggle();
Expand All @@ -3723,7 +3744,9 @@ function btn(el) {

function collapse(el) {
el = getNode(el);

if (el == null) {
return
}
on(el, 'click', function (ref) {
var target = ref.target;

Expand Down Expand Up @@ -3761,8 +3784,10 @@ function sticky() {
*/
function getAndActive(router, el, isParent, autoTitle) {
el = getNode(el);

var links = findAll(el, 'a');
var links = [];
if (el != null) {
links = findAll(el, 'a');
}
var hash = decodeURI(router.toURL(router.getCurrentPath()));
var target;

Expand Down Expand Up @@ -3965,7 +3990,10 @@ function scrollActiveSidebar(router) {
coverHeight = cover ? cover.offsetHeight : 0;

var sidebar = getNode('.sidebar');
var lis = findAll(sidebar, 'li');
var lis = [];
if (sidebar != null) {
lis = findAll(sidebar, 'li');
}

for (var i = 0, len = lis.length; i < len; i += 1) {
var li = lis[i];
Expand Down Expand Up @@ -4049,6 +4077,11 @@ function walkFetchEmbed(ref, cb) {
if (token.embed.type === 'markdown') {
embedToken = compile.lexer(text);
} else if (token.embed.type === 'code') {
if (token.embed.fragment) {
var fragment = token.embed.fragment;
var pattern = new RegExp(("(?:###|\\/\\/\\/)\\s*\\[" + fragment + "\\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[" + fragment + "\\]"));
text = ((text.match(pattern) || [])[1] || '').trim();
}
embedToken = compile.lexer(
'```' +
token.embed.lang +
Expand Down Expand Up @@ -5013,7 +5046,7 @@ function initGlobalAPI () {
dom: dom,
get: get,
slugify: slugify,
version: '4.8.6'
version: '4.9.0'
};
window.DocsifyCompiler = Compiler;
window.marked = marked;
Expand Down
2 changes: 1 addition & 1 deletion lib/docsify.min.js

Large diffs are not rendered by default.

32 changes: 25 additions & 7 deletions lib/plugins/search.js
Original file line number Diff line number Diff line change
@@ -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 = {
'&': '&amp;',
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = {};
Expand All @@ -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);
});
});
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/search.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d1c7268

Please sign in to comment.