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

@ -1,6 +1,6 @@
![logo](_media/icon.svg) ![logo](_media/icon.svg)
# docsify <small>2.2.1</small> # docsify <small>2.3.0</small>
> A magical documentation site generator. > A magical documentation site generator.

View file

@ -176,7 +176,6 @@ function emojify (text) {
} }
var utils = Object.freeze({ var utils = Object.freeze({
load: load, load: load,
genTree: genTree, genTree: genTree,
@ -208,7 +207,9 @@ function scrollActiveSidebar () {
for (var i = 0, len = lis.length; i < len; i += 1) { for (var i = 0, len = lis.length; i < len; i += 1) {
var li = lis[i]; var li = lis[i];
var href = li.querySelector('a').getAttribute('href'); var a = li.querySelector('a');
if (!a) { continue }
var href = a.getAttribute('href');
if (href !== '/') { if (href !== '/') {
var match = href.match('#([^#]+)$'); var match = href.match('#([^#]+)$');
@ -322,10 +323,12 @@ function bindToggle (dom) {
} }
} }
var scrollingElement = document.scrollingElement || document.documentElement;
function scroll2Top (offset) { function scroll2Top (offset) {
if ( offset === void 0 ) offset = 0; if ( offset === void 0 ) offset = 0;
document.body.scrollTop = offset === true ? 0 : Number(offset); scrollingElement.scrollTop = offset === true ? 0 : Number(offset);
} }
function sticky () { function sticky () {
@ -2543,6 +2546,7 @@ function cssVars () {
var markdown = marked; var markdown = marked;
var toc = []; var toc = [];
var CACHE = {}; var CACHE = {};
var originTitle = document.title;
var renderTo = function (dom, content) { var renderTo = function (dom, content) {
dom = typeof dom === 'object' ? dom : document.querySelector(dom); dom = typeof dom === 'object' ? dom : document.querySelector(dom);
@ -2579,10 +2583,9 @@ function init () {
return ("<pre v-pre data-lang=\"" + lang + "\"><code class=\"lang-" + lang + "\">" + hl + "</code></pre>") return ("<pre v-pre data-lang=\"" + lang + "\"><code class=\"lang-" + lang + "\">" + hl + "</code></pre>")
}; };
renderer.link = function (href, title, text) { renderer.link = function (href, title, text) {
if (!/:/.test(href)) { if (!/:|(\/{2})/.test(href)) {
href = ("#/" + href).replace(/\/+/g, '/'); href = ("#/" + href).replace(/\/+/g, '/');
} }
return ("<a href=\"" + href + "\" title=\"" + (title || '') + "\">" + text + "</a>") return ("<a href=\"" + href + "\" title=\"" + (title || '') + "\">" + text + "</a>")
}; };
renderer.paragraph = function (text) { renderer.paragraph = function (text) {
@ -2593,11 +2596,19 @@ function init () {
} }
return ("<p>" + text + "</p>") return ("<p>" + text + "</p>")
}; };
renderer.image = function (href, title, text) {
var url = /:|(\/{2})/.test(href) ? href : ($docsify.basePath + href).replace(/\/+/g, '/');
var titleHTML = title ? (" title=\"" + title + "\"") : '';
return ("<img src=\"" + url + "\" alt=\"" + text + "\"" + titleHTML + " />")
};
if (typeof $docsify.markdown === 'function') { if (typeof $docsify.markdown === 'function') {
markdown.setOptions({ renderer: renderer }); markdown = $docsify.markdown.call(this, markdown, renderer);
markdown = $docsify.markdown.call(this, markdown);
} else { } else {
if ($docsify.markdown && $docsify.markdown.renderer) {
$docsify.markdown.renderer = merge(renderer, $docsify.markdown.renderer);
}
markdown.setOptions(merge({ renderer: renderer }, $docsify.markdown)); markdown.setOptions(merge({ renderer: renderer }, $docsify.markdown));
} }
@ -2653,25 +2664,34 @@ function renderApp (dom, replace) {
* article * article
*/ */
function renderArticle (content) { function renderArticle (content) {
renderTo('article', content ? markdown(content) : 'not found'); var hook = window.Docsify.hook;
if (!$docsify.loadSidebar) { renderSidebar(); } var renderFn = function (data) {
renderTo('article', data);
if (!$docsify.loadSidebar) { renderSidebar(); }
if (content && typeof Vue !== 'undefined') { if (data && typeof Vue !== 'undefined') {
CACHE.vm && CACHE.vm.$destroy(); CACHE.vm && CACHE.vm.$destroy();
var script = [].slice.call( var script = [].slice.call(
document.body.querySelectorAll('article>script')) document.body.querySelectorAll('article>script'))
.filter(function (script) { return !/template/.test(script.type); } .filter(function (script) { return !/template/.test(script.type); }
)[0]; )[0];
var code = script ? script.innerText.trim() : null; var code = script ? script.innerText.trim() : null;
script && script.remove(); script && script.remove();
CACHE.vm = code CACHE.vm = code
? new Function(("return " + code))() ? new Function(("return " + code))()
: new Vue({ el: 'main' }); // eslint-disable-line : new Vue({ el: 'main' }); // eslint-disable-line
CACHE.vm && CACHE.vm.$nextTick(function (_) { return scrollActiveSidebar(); }); 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); }
};
hook.emit('before', content, function (result) {
var html = result ? markdown(result) : '';
hook.emit('after', html, function (result) { return renderFn(result || 'not found'); });
});
} }
/** /**
@ -2700,15 +2720,21 @@ function renderSidebar (content) {
} }
renderTo('.sidebar-nav', html); renderTo('.sidebar-nav', html);
if (toc[0] && toc[0].level === 1) {
document.title = "" + (toc[0].title) + (originTitle ? ' - ' + originTitle : '');
}
var target = activeLink('.sidebar-nav', true); var target = activeLink('.sidebar-nav', true);
if (target) { renderSubSidebar(target); } if (target) { renderSubSidebar(target); }
toc = [];
toc = [];
scrollActiveSidebar(); scrollActiveSidebar();
} }
function renderSubSidebar (target) { function renderSubSidebar (target) {
if (!$docsify.subMaxLevel) { return } if (!$docsify.subMaxLevel) { return }
toc[0] && toc[0].level === 1 && toc.shift();
target.parentNode.innerHTML += tree(genTree(toc, $docsify.subMaxLevel), '<ul>'); target.parentNode.innerHTML += tree(genTree(toc, $docsify.subMaxLevel), '<ul>');
} }
@ -2787,6 +2813,57 @@ function renderLoading (ref) {
} }
} }
var Hook = function Hook () {
this.beforeHooks = [];
this.afterHooks = [];
this.initHooks = [];
this.readyHooks = [];
};
Hook.prototype.beforeEach = function beforeEach (fn) {
this.beforeHooks.push(fn);
};
Hook.prototype.afterEach = function afterEach (fn) {
this.afterHooks.push(fn);
};
Hook.prototype.init = function init (fn) {
this.initHooks.push(fn);
};
Hook.prototype.ready = function ready (fn) {
this.readyHooks.push(fn);
};
Hook.prototype.emit = function emit (name, data, next) {
var newData = data;
var queue = this[name + 'Hooks'];
var step = function (index) {
var hook = queue[index];
if (index >= queue.length) {
next && next(newData);
} else {
if (typeof hook === 'function') {
if (hook.length === 2) {
hook(data, function (result) {
newData = result;
step(index + 1);
});
} else {
var result = hook(data);
newData = result !== undefined ? result : newData;
step(index + 1);
}
} else {
step(index + 1);
}
}
};
step(0);
};
var OPTIONS = merge({ var OPTIONS = merge({
el: '#app', el: '#app',
repo: '', repo: '',
@ -2818,11 +2895,14 @@ if (script) {
if (OPTIONS.name === true) { OPTIONS.name = ''; } if (OPTIONS.name === true) { OPTIONS.name = ''; }
} }
var hook = new Hook();
// utils // utils
window.$docsify = OPTIONS; window.$docsify = OPTIONS;
window.Docsify = { window.Docsify = {
installed: true, installed: true,
utils: merge({}, utils) utils: merge({}, utils),
hook: hook
}; };
// load options // load options
@ -2831,11 +2911,20 @@ init();
var cacheRoute = null; var cacheRoute = null;
var cacheXhr = null; var cacheXhr = null;
var getAlias = function (route) {
if (OPTIONS.alias[route]) {
return getAlias(OPTIONS.alias[route])
} else {
return route
}
};
var mainRender = function (cb) { var mainRender = function (cb) {
var route = OPTIONS.basePath + getRoute(); var page;
var route = getRoute();
if (cacheRoute === route) { return cb() } if (cacheRoute === route) { return cb() }
var basePath = cacheRoute = route; var basePath = cacheRoute = OPTIONS.basePath + route;
if (!/\//.test(basePath)) { if (!/\//.test(basePath)) {
basePath = ''; basePath = '';
@ -2843,10 +2932,18 @@ var mainRender = function (cb) {
basePath = basePath.match(/(\S*\/)[^\/]+$/)[1]; basePath = basePath.match(/(\S*\/)[^\/]+$/)[1];
} }
var page; // replace route
route = '/' + route;
if (OPTIONS.alias && OPTIONS.alias[route]) {
route = getAlias(route);
} else {
route = (OPTIONS.basePath + route).replace(/\/+/, '/');
}
if (!route) { if (!route) {
page = OPTIONS.homepage || 'README.md'; page = OPTIONS.homepage || 'README.md';
} else if (/\.md$/.test(route)) {
page = route;
} else if (/\/$/.test(route)) { } else if (/\/$/.test(route)) {
page = route + "README.md"; page = route + "README.md";
} else { } else {
@ -2884,21 +2981,26 @@ var mainRender = function (cb) {
}; };
var Docsify = function () { var Docsify = function () {
var dom = document.querySelector(OPTIONS.el) || document.body; setTimeout(function (_) {
var replace = dom !== document.body; [].concat(OPTIONS.plugins).forEach(function (fn) { return typeof fn === 'function' && fn(hook); });
var main = function () { window.Docsify.hook.emit('init');
mainRender(function (_) {
scrollIntoView();
activeLink('nav')
;[].concat(window.$docsify.plugins).forEach(function (fn) { return fn && fn(); });
});
};
// Render app var dom = document.querySelector(OPTIONS.el) || document.body;
renderApp(dom, replace); var replace = dom !== document.body;
main(); var main = function () {
if (!/^#\//.test(window.location.hash)) { window.location.hash = '#/'; } mainRender(function (_) {
window.addEventListener('hashchange', main); scrollIntoView();
activeLink('nav');
});
};
// Render app
renderApp(dom, replace);
main();
if (!/^#\//.test(window.location.hash)) { window.location.hash = '#/'; }
window.addEventListener('hashchange', main);
window.Docsify.hook.emit('ready');
}, 0);
}; };
var index = Docsify(); var index = Docsify();

4
lib/docsify.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -29,18 +29,18 @@ function collect () {
} }
var install = function () { var install = function () {
if (!window.Docsify || !window.Docsify.installed) { if (install.installed) { return }
console.error('[Docsify] Please load docsify.js first.'); install.installed = true;
return
}
if (!window.$docsify.ga) { if (!window.$docsify.ga) {
console.error('[Docsify] ga is required.'); console.error('[Docsify] ga is required.');
return return
} }
collect(); window.$docsify.plugins = [].concat(function (hook) {
window.$docsify.plugins = [].concat(window.$docsify.plugins, collect); hook.init(collect);
hook.beforeEach(collect);
}, window.$docsify.plugins);
}; };
var ga = install(); var ga = install();

View file

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

View file

@ -46,8 +46,9 @@ var getAllPaths = function () {
/** /**
* return file path * return file path
*/ */
var genFilePath = function (path) { var genFilePath = function (path, basePath) {
var basePath = window.$docsify.basePath; if ( basePath === void 0 ) basePath = window.$docsify.basePath;
var filePath = /\/$/.test(path) ? (path + "README.md") : (path + ".md"); var filePath = /\/$/.test(path) ? (path + "README.md") : (path + ".md");
filePath = basePath + filePath; filePath = basePath + filePath;
@ -240,6 +241,7 @@ var searchPlugin = function () {
var load = ref.load; var load = ref.load;
var marked = ref.marked; var marked = ref.marked;
var slugify = ref.slugify; var slugify = ref.slugify;
var alias = window.$docsify.alias;
var done = function () { var done = function () {
localStorage.setItem('docsify.search.expires', Date.now() + CONFIG.maxAge); localStorage.setItem('docsify.search.expires', Date.now() + CONFIG.maxAge);
localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS)); localStorage.setItem('docsify.search.index', JSON.stringify(INDEXS));
@ -247,8 +249,16 @@ var searchPlugin = function () {
paths.forEach(function (path) { paths.forEach(function (path) {
if (INDEXS[path]) { return count++ } 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)); genIndex(path, marked(content));
slugify.clear(); slugify.clear();
count++; count++;
@ -259,12 +269,8 @@ var searchPlugin = function () {
}; };
var install = function () { var install = function () {
if (!window.Docsify || !window.Docsify.installed) { if (install.installed) { return }
console.error('[Docsify] Please load docsify.js first.'); install.installed = true;
return
}
window.$docsify.plugins = [].concat(window.$docsify.plugins, searchPlugin);
var userConfig = window.$docsify.search; var userConfig = window.$docsify.search;
var isNil = window.Docsify.utils.isNil; var isNil = window.Docsify.utils.isNil;
@ -277,7 +283,15 @@ var install = function () {
CONFIG.placeholder = userConfig.placeholder || CONFIG.placeholder; 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(); var search = install();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
lib/themes/dark.css Normal file

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