mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
bump 2.3.0
This commit is contained in:
parent
bf559b44dc
commit
ec8b17bd43
@ -1,6 +1,6 @@
|
||||

|
||||
|
||||
# docsify <small>2.2.1</small>
|
||||
# docsify <small>2.3.0</small>
|
||||
|
||||
> A magical documentation site generator.
|
||||
|
||||
|
||||
186
lib/docsify.js
186
lib/docsify.js
@ -176,7 +176,6 @@ function emojify (text) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
var utils = Object.freeze({
|
||||
load: load,
|
||||
genTree: genTree,
|
||||
@ -208,7 +207,9 @@ function scrollActiveSidebar () {
|
||||
|
||||
for (var i = 0, len = lis.length; i < len; i += 1) {
|
||||
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 !== '/') {
|
||||
var match = href.match('#([^#]+)$');
|
||||
@ -322,10 +323,12 @@ function bindToggle (dom) {
|
||||
}
|
||||
}
|
||||
|
||||
var scrollingElement = document.scrollingElement || document.documentElement;
|
||||
|
||||
function scroll2Top (offset) {
|
||||
if ( offset === void 0 ) offset = 0;
|
||||
|
||||
document.body.scrollTop = offset === true ? 0 : Number(offset);
|
||||
scrollingElement.scrollTop = offset === true ? 0 : Number(offset);
|
||||
}
|
||||
|
||||
function sticky () {
|
||||
@ -2543,6 +2546,7 @@ function cssVars () {
|
||||
var markdown = marked;
|
||||
var toc = [];
|
||||
var CACHE = {};
|
||||
var originTitle = document.title;
|
||||
|
||||
var renderTo = function (dom, content) {
|
||||
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>")
|
||||
};
|
||||
renderer.link = function (href, title, text) {
|
||||
if (!/:/.test(href)) {
|
||||
if (!/:|(\/{2})/.test(href)) {
|
||||
href = ("#/" + href).replace(/\/+/g, '/');
|
||||
}
|
||||
|
||||
return ("<a href=\"" + href + "\" title=\"" + (title || '') + "\">" + text + "</a>")
|
||||
};
|
||||
renderer.paragraph = function (text) {
|
||||
@ -2593,11 +2596,19 @@ function init () {
|
||||
}
|
||||
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') {
|
||||
markdown.setOptions({ renderer: renderer });
|
||||
markdown = $docsify.markdown.call(this, markdown);
|
||||
markdown = $docsify.markdown.call(this, markdown, renderer);
|
||||
} else {
|
||||
if ($docsify.markdown && $docsify.markdown.renderer) {
|
||||
$docsify.markdown.renderer = merge(renderer, $docsify.markdown.renderer);
|
||||
}
|
||||
markdown.setOptions(merge({ renderer: renderer }, $docsify.markdown));
|
||||
}
|
||||
|
||||
@ -2653,25 +2664,34 @@ function renderApp (dom, replace) {
|
||||
* article
|
||||
*/
|
||||
function renderArticle (content) {
|
||||
renderTo('article', content ? markdown(content) : 'not found');
|
||||
if (!$docsify.loadSidebar) { renderSidebar(); }
|
||||
var hook = window.Docsify.hook;
|
||||
var renderFn = function (data) {
|
||||
renderTo('article', data);
|
||||
if (!$docsify.loadSidebar) { renderSidebar(); }
|
||||
|
||||
if (content && typeof Vue !== 'undefined') {
|
||||
CACHE.vm && CACHE.vm.$destroy();
|
||||
if (data && typeof Vue !== 'undefined') {
|
||||
CACHE.vm && CACHE.vm.$destroy();
|
||||
|
||||
var script = [].slice.call(
|
||||
document.body.querySelectorAll('article>script'))
|
||||
.filter(function (script) { return !/template/.test(script.type); }
|
||||
)[0];
|
||||
var code = script ? script.innerText.trim() : null;
|
||||
var script = [].slice.call(
|
||||
document.body.querySelectorAll('article>script'))
|
||||
.filter(function (script) { return !/template/.test(script.type); }
|
||||
)[0];
|
||||
var code = script ? script.innerText.trim() : null;
|
||||
|
||||
script && script.remove();
|
||||
CACHE.vm = code
|
||||
? new Function(("return " + code))()
|
||||
: new Vue({ el: 'main' }); // eslint-disable-line
|
||||
CACHE.vm && CACHE.vm.$nextTick(function (_) { return scrollActiveSidebar(); });
|
||||
}
|
||||
if ($docsify.auto2top) { setTimeout(function () { return scroll2Top($docsify.auto2top); }, 0); }
|
||||
script && script.remove();
|
||||
CACHE.vm = code
|
||||
? new Function(("return " + code))()
|
||||
: new Vue({ el: 'main' }); // eslint-disable-line
|
||||
CACHE.vm && CACHE.vm.$nextTick(function (_) { return scrollActiveSidebar(); });
|
||||
}
|
||||
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);
|
||||
|
||||
if (toc[0] && toc[0].level === 1) {
|
||||
document.title = "" + (toc[0].title) + (originTitle ? ' - ' + originTitle : '');
|
||||
}
|
||||
|
||||
var target = activeLink('.sidebar-nav', true);
|
||||
if (target) { renderSubSidebar(target); }
|
||||
toc = [];
|
||||
|
||||
toc = [];
|
||||
scrollActiveSidebar();
|
||||
}
|
||||
|
||||
function renderSubSidebar (target) {
|
||||
if (!$docsify.subMaxLevel) { return }
|
||||
toc[0] && toc[0].level === 1 && toc.shift();
|
||||
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({
|
||||
el: '#app',
|
||||
repo: '',
|
||||
@ -2818,11 +2895,14 @@ if (script) {
|
||||
if (OPTIONS.name === true) { OPTIONS.name = ''; }
|
||||
}
|
||||
|
||||
var hook = new Hook();
|
||||
|
||||
// utils
|
||||
window.$docsify = OPTIONS;
|
||||
window.Docsify = {
|
||||
installed: true,
|
||||
utils: merge({}, utils)
|
||||
utils: merge({}, utils),
|
||||
hook: hook
|
||||
};
|
||||
|
||||
// load options
|
||||
@ -2831,11 +2911,20 @@ init();
|
||||
var cacheRoute = 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 route = OPTIONS.basePath + getRoute();
|
||||
var page;
|
||||
var route = getRoute();
|
||||
if (cacheRoute === route) { return cb() }
|
||||
|
||||
var basePath = cacheRoute = route;
|
||||
var basePath = cacheRoute = OPTIONS.basePath + route;
|
||||
|
||||
if (!/\//.test(basePath)) {
|
||||
basePath = '';
|
||||
@ -2843,10 +2932,18 @@ var mainRender = function (cb) {
|
||||
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) {
|
||||
page = OPTIONS.homepage || 'README.md';
|
||||
} else if (/\.md$/.test(route)) {
|
||||
page = route;
|
||||
} else if (/\/$/.test(route)) {
|
||||
page = route + "README.md";
|
||||
} else {
|
||||
@ -2884,21 +2981,26 @@ var mainRender = function (cb) {
|
||||
};
|
||||
|
||||
var Docsify = function () {
|
||||
var dom = document.querySelector(OPTIONS.el) || document.body;
|
||||
var replace = dom !== document.body;
|
||||
var main = function () {
|
||||
mainRender(function (_) {
|
||||
scrollIntoView();
|
||||
activeLink('nav')
|
||||
;[].concat(window.$docsify.plugins).forEach(function (fn) { return fn && fn(); });
|
||||
});
|
||||
};
|
||||
setTimeout(function (_) {
|
||||
[].concat(OPTIONS.plugins).forEach(function (fn) { return typeof fn === 'function' && fn(hook); });
|
||||
window.Docsify.hook.emit('init');
|
||||
|
||||
// Render app
|
||||
renderApp(dom, replace);
|
||||
main();
|
||||
if (!/^#\//.test(window.location.hash)) { window.location.hash = '#/'; }
|
||||
window.addEventListener('hashchange', main);
|
||||
var dom = document.querySelector(OPTIONS.el) || document.body;
|
||||
var replace = dom !== document.body;
|
||||
var main = function () {
|
||||
mainRender(function (_) {
|
||||
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();
|
||||
|
||||
4
lib/docsify.min.js
vendored
4
lib/docsify.min.js
vendored
File diff suppressed because one or more lines are too long
@ -29,18 +29,18 @@ function collect () {
|
||||
}
|
||||
|
||||
var install = function () {
|
||||
if (!window.Docsify || !window.Docsify.installed) {
|
||||
console.error('[Docsify] Please load docsify.js first.');
|
||||
return
|
||||
}
|
||||
if (install.installed) { return }
|
||||
install.installed = true;
|
||||
|
||||
if (!window.$docsify.ga) {
|
||||
console.error('[Docsify] ga is required.');
|
||||
return
|
||||
}
|
||||
|
||||
collect();
|
||||
window.$docsify.plugins = [].concat(window.$docsify.plugins, collect);
|
||||
window.$docsify.plugins = [].concat(function (hook) {
|
||||
hook.init(collect);
|
||||
hook.beforeEach(collect);
|
||||
}, window.$docsify.plugins);
|
||||
};
|
||||
|
||||
var ga = install();
|
||||
|
||||
2
lib/plugins/ga.min.js
vendored
2
lib/plugins/ga.min.js
vendored
@ -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}();
|
||||
|
||||
@ -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();
|
||||
|
||||
2
lib/plugins/search.min.js
vendored
2
lib/plugins/search.min.js
vendored
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
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
Loading…
x
Reference in New Issue
Block a user