bump: 3.7.0

This commit is contained in:
qingwei.li 2017-05-16 23:11:50 +08:00
commit 50e771e6a8
No known key found for this signature in database
GPG key ID: B6DDC2F7AE80B2F4
3 changed files with 83 additions and 14 deletions

View file

@ -1,5 +1,11 @@
# Changelog
## 3.7.0 / 2017-05-16
* feat: add externalLinkTarget, close #149
* feat: add **{docsify-updated<span>}</span>**, close #158
## 3.6.6 / 2017-05-06
* feat: support query string for the search, likes `https://docsify.js.org/#/?s=navbar`, fixed ([#156](https://github.com/QingWei-Li/docsify/issues/156)

View file

@ -77,7 +77,9 @@ var config = merge({
executeScript: null,
noEmoji: false,
ga: '',
mergeNavbar: false
mergeNavbar: false,
formatUpdated: '',
externalLinkTarget: '_blank'
}, window.$docsify);
var script = document.currentScript ||
@ -629,9 +631,10 @@ function get (url, hasBar) {
var on = function () {
xhr.addEventListener.apply(xhr, arguments);
};
var cached$$1 = cache[url];
if (cache[url]) {
return { then: function (cb) { return cb(cache[url]); }, abort: noop }
if (cached$$1) {
return { then: function (cb) { return cb(cached$$1.content, cached$$1.opt); }, abort: noop }
}
xhr.open('GET', url);
@ -660,8 +663,14 @@ function get (url, hasBar) {
if (target.status >= 400) {
error(target);
} else {
cache[url] = target.response;
success(target.response);
var result = cache[url] = {
content: target.response,
opt: {
updatedAt: xhr.getResponseHeader('last-modified')
}
};
success(result.content, result.opt);
}
});
},
@ -2959,6 +2968,7 @@ function emojify (text) {
var markdownCompiler = marked;
var contentBase = '';
var currentPath = '';
var linkTarget = '_blank';
var renderer = new marked.Renderer();
var cacheTree = {};
var toc = [];
@ -2980,11 +2990,13 @@ var markdown = cached(function (text) {
markdown.renderer = renderer;
markdown.init = function (config, base) {
markdown.init = function (config, ref) {
if ( config === void 0 ) config = {};
if ( base === void 0 ) base = window.location.pathname;
var base = ref.base; if ( base === void 0 ) base = window.location.pathname;
var externalLinkTarget = ref.externalLinkTarget;
contentBase = getBasePath(base);
linkTarget = externalLinkTarget || linkTarget;
if (isFn(config)) {
markdownCompiler = config(marked, renderer);
@ -3037,7 +3049,7 @@ renderer.link = function (href, title, text) {
if (!/:|(\/{2})/.test(href)) {
href = toURL(href, null, currentPath);
} else {
blank = ' target="_blank"';
blank = " target=\"" + linkTarget + "\"";
}
if (title) {
title = " title=\"" + title + "\"";
@ -3118,6 +3130,45 @@ var render = Object.freeze({
cover: cover$1
});
var RGX = /([^{]*?)\w(?=\})/g;
var dict = {
YYYY: 'getFullYear',
YY: 'getYear',
MM: function (d) {
return d.getMonth() + 1;
},
DD: 'getDate',
HH: 'getHours',
mm: 'getMinutes',
ss: 'getSeconds'
};
var tinydate = function (str) {
var parts=[], offset=0;
str.replace(RGX, function (key, _, idx) {
// save preceding string
parts.push(str.substring(offset, idx - 1));
offset = idx += key.length + 1;
// save function
parts.push(function(d){
return ('00' + (typeof dict[key]==='string' ? d[dict[key]]() : dict[key](d))).slice(-key.length);
});
});
if (offset !== str.length) {
parts.push(str.substring(offset));
}
return function (arg) {
var out='', i=0, d=arg||new Date();
for (; i<parts.length; i++) {
out += (typeof parts[i]==='string') ? parts[i] : parts[i](d);
}
return out;
};
};
function executeScript () {
var script = findAll('.markdown-section>script')
.filter(function (s) { return !/template/.test(s.type); })[0];
@ -3130,6 +3181,16 @@ function executeScript () {
}, 0);
}
function formatUpdated (html, updated, fn) {
updated = typeof fn === 'function'
? fn(updated)
: typeof fn === 'string'
? tinydate(fn)(new Date(updated))
: updated;
return html.replace(/{docsify-updated}/g, updated)
}
function renderMain (html) {
if (!html) {
// TODO: Custom 404 page
@ -3210,11 +3271,13 @@ function renderMixin (proto) {
getAndActive('nav');
};
proto._renderMain = function (text) {
proto._renderMain = function (text, opt) {
var this$1 = this;
callHook(this, 'beforeEach', text, function (result) {
var html = this$1.isHTML ? result : markdown(result);
html = formatUpdated(html, opt.updatedAt, this$1.config.formatUpdated);
callHook(this$1, 'afterEach', html, function (text) { return renderMain.call(this$1, text); });
});
};
@ -3262,7 +3325,7 @@ function initRender (vm) {
var config = vm.config;
// Init markdown compiler
markdown.init(config.markdown, config.basePath);
markdown.init(config.markdown, config);
var id = config.el || '#app';
var navEl = find('nav') || create('nav');
@ -3406,8 +3469,8 @@ function fetchMixin (proto) {
this.isHTML = /\.html$/g.test(path);
// Load main content
last.then(function (text) {
this$1._renderMain(text);
last.then(function (text, opt) {
this$1._renderMain(text, opt);
if (!loadSidebar) { return cb() }
var fn = function (result) { this$1._renderSidebar(result); cb(); };

4
lib/docsify.min.js vendored

File diff suppressed because one or more lines are too long