mirror of
https://github.com/wahyd4/docsify.git
synced 2026-08-10 22:06:24 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eda9bb8343 | ||
|
|
50e771e6a8 | ||
|
|
2d73285de5 | ||
|
|
d2be5aecf8 |
@@ -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)
|
||||
|
||||
@@ -4,7 +4,7 @@ var fs = require('fs')
|
||||
|
||||
http.createServer(function (req, res) {
|
||||
serveStatic('.')(req, res, function () {
|
||||
res.writeHead(404, { 'Content-Type': 'text/html' })
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' })
|
||||
res.end(fs.readFileSync('dev.html'))
|
||||
})
|
||||
}).listen(3000, '0.0.0.0')
|
||||
|
||||
@@ -30,7 +30,15 @@
|
||||
loadSidebar: true,
|
||||
name: 'docsify',
|
||||
subMaxLevel: 2,
|
||||
mergeNavbar: true
|
||||
mergeNavbar: true,
|
||||
formatUpdated: '{MM}/{DD} {HH}:{mm}',
|
||||
plugins: [
|
||||
function(hook) {
|
||||
hook.beforeEach(function (html) {
|
||||
return html += '> Last modified {docsify-updated}'
|
||||
})
|
||||
}
|
||||
]
|
||||
}
|
||||
</script>
|
||||
<script src="/lib/docsify.js"></script>
|
||||
|
||||
@@ -315,3 +315,28 @@ window.$docsify = {
|
||||
mergeNavbar: true
|
||||
}
|
||||
```
|
||||
|
||||
## format-updated
|
||||
We can display the file update date through **{docsify-updated<span>}</span>** variable. And format it by `formatUpdated`.
|
||||
See https://github.com/lukeed/tinydate#patterns
|
||||
```js
|
||||
window.$docsify = {
|
||||
formatUpdated: '{MM}/{DD} {HH}:{mm}',
|
||||
|
||||
formatUpdated: function (time) {
|
||||
// ...
|
||||
|
||||
return time
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## external-link-target
|
||||
|
||||
Currently it defaults to _blank, would be nice if configurable:
|
||||
|
||||
```js
|
||||
window.$docsify = {
|
||||
externalLinkTarget: '_self' // default: '_blank'
|
||||
}
|
||||
```
|
||||
|
||||
@@ -314,4 +314,29 @@ Navbar will be merged with the sidebar on smaller screens.
|
||||
window.$docsify = {
|
||||
mergeNavbar: true
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
## format-updated
|
||||
We can display the file update date through **{docsify-updated<span>}</span>** variable. And format it by `formatUpdated`.
|
||||
See https://github.com/lukeed/tinydate#patterns
|
||||
```js
|
||||
window.$docsify = {
|
||||
formatUpdated: '{MM}/{DD} {HH}:{mm}',
|
||||
|
||||
formatUpdated: function (time) {
|
||||
// ...
|
||||
|
||||
return time
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## external-link-target
|
||||
|
||||
Currently it defaults to _blank, would be nice if configurable:
|
||||
|
||||
```js
|
||||
window.$docsify = {
|
||||
externalLinkTarget: '_self' // default: '_blank'
|
||||
}
|
||||
```
|
||||
|
||||
+9
-1
@@ -34,6 +34,7 @@
|
||||
loadNavbar: true,
|
||||
mergeNavbar: true,
|
||||
maxLevel: 4,
|
||||
subMaxLevel: 2,
|
||||
name: 'docsify',
|
||||
search: {
|
||||
noData: {
|
||||
@@ -48,7 +49,14 @@
|
||||
'/': 'Search'
|
||||
}
|
||||
},
|
||||
subMaxLevel: 2
|
||||
formatUpdated: '{MM}/{DD} {HH}:{mm}',
|
||||
plugins: [
|
||||
function(hook) {
|
||||
hook.beforeEach(function (html) {
|
||||
return html += '> Last modified {docsify-updated}'
|
||||
})
|
||||
}
|
||||
]
|
||||
}
|
||||
</script>
|
||||
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||
|
||||
@@ -326,3 +326,27 @@ window.$docsify = {
|
||||
}
|
||||
```
|
||||
|
||||
## format-updated
|
||||
我们可以显示文档更新日期通过 **{docsify-updated<span>}</span>** 变量. 并且格式化日期通过 `formatUpdated`.
|
||||
参考 https://github.com/lukeed/tinydate#patterns
|
||||
```js
|
||||
window.$docsify = {
|
||||
formatUpdated: '{MM}/{DD} {HH}:{mm}',
|
||||
|
||||
formatUpdated: function (time) {
|
||||
// ...
|
||||
|
||||
return time
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## external-link-target
|
||||
|
||||
Currently it defaults to _blank, would be nice if configurable:
|
||||
|
||||
```js
|
||||
window.$docsify = {
|
||||
externalLinkTarget: '_self' // default: '_blank'
|
||||
}
|
||||
```
|
||||
|
||||
+75
-12
@@ -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(); };
|
||||
|
||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
+2
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docsify",
|
||||
"version": "3.6.6",
|
||||
"version": "3.7.0",
|
||||
"description": "A magical documentation generator.",
|
||||
"author": {
|
||||
"name": "qingwei-li",
|
||||
@@ -28,6 +28,7 @@
|
||||
"dependencies": {
|
||||
"marked": "^0.3.6",
|
||||
"prismjs": "^1.6.0",
|
||||
"tinydate": "^1.0.0",
|
||||
"zoom-image": "^0.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
+3
-1
@@ -18,7 +18,9 @@ const config = merge({
|
||||
executeScript: null,
|
||||
noEmoji: false,
|
||||
ga: '',
|
||||
mergeNavbar: false
|
||||
mergeNavbar: false,
|
||||
formatUpdated: '',
|
||||
externalLinkTarget: '_blank'
|
||||
}, window.$docsify)
|
||||
|
||||
const script = document.currentScript ||
|
||||
|
||||
+11
-4
@@ -14,9 +14,10 @@ export function get (url, hasBar = false) {
|
||||
const on = function () {
|
||||
xhr.addEventListener.apply(xhr, arguments)
|
||||
}
|
||||
const cached = cache[url]
|
||||
|
||||
if (cache[url]) {
|
||||
return { then: cb => cb(cache[url]), abort: noop }
|
||||
if (cached) {
|
||||
return { then: cb => cb(cached.content, cached.opt), abort: noop }
|
||||
}
|
||||
|
||||
xhr.open('GET', url)
|
||||
@@ -41,8 +42,14 @@ export function get (url, hasBar = false) {
|
||||
if (target.status >= 400) {
|
||||
error(target)
|
||||
} else {
|
||||
cache[url] = target.response
|
||||
success(target.response)
|
||||
const result = cache[url] = {
|
||||
content: target.response,
|
||||
opt: {
|
||||
updatedAt: xhr.getResponseHeader('last-modified')
|
||||
}
|
||||
}
|
||||
|
||||
success(result.content, result.opt)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@@ -28,8 +28,8 @@ export function fetchMixin (proto) {
|
||||
this.isHTML = /\.html$/g.test(path)
|
||||
|
||||
// Load main content
|
||||
last.then(text => {
|
||||
this._renderMain(text)
|
||||
last.then((text, opt) => {
|
||||
this._renderMain(text, opt)
|
||||
if (!loadSidebar) return cb()
|
||||
|
||||
const fn = result => { this._renderSidebar(result); cb() }
|
||||
|
||||
@@ -11,6 +11,7 @@ import { isFn, merge, cached } from '../util/core'
|
||||
let markdownCompiler = marked
|
||||
let contentBase = ''
|
||||
let currentPath = ''
|
||||
let linkTarget = '_blank'
|
||||
let renderer = new marked.Renderer()
|
||||
const cacheTree = {}
|
||||
let toc = []
|
||||
@@ -32,8 +33,12 @@ export const markdown = cached(text => {
|
||||
|
||||
markdown.renderer = renderer
|
||||
|
||||
markdown.init = function (config = {}, base = window.location.pathname) {
|
||||
markdown.init = function (config = {}, {
|
||||
base = window.location.pathname,
|
||||
externalLinkTarget
|
||||
}) {
|
||||
contentBase = getBasePath(base)
|
||||
linkTarget = externalLinkTarget || linkTarget
|
||||
|
||||
if (isFn(config)) {
|
||||
markdownCompiler = config(marked, renderer)
|
||||
@@ -84,7 +89,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}"`
|
||||
|
||||
@@ -8,6 +8,7 @@ import { callHook } from '../init/lifecycle'
|
||||
import { getBasePath, getPath, isAbsolutePath } from '../route/util'
|
||||
import { isPrimitive } from '../util/core'
|
||||
import { isMobile } from '../util/env'
|
||||
import tinydate from 'tinydate'
|
||||
|
||||
function executeScript () {
|
||||
const script = dom.findAll('.markdown-section>script')
|
||||
@@ -21,6 +22,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
|
||||
@@ -97,9 +108,11 @@ export function renderMixin (proto) {
|
||||
getAndActive('nav')
|
||||
}
|
||||
|
||||
proto._renderMain = function (text) {
|
||||
proto._renderMain = function (text, opt) {
|
||||
callHook(this, 'beforeEach', text, result => {
|
||||
const html = this.isHTML ? result : markdown(result)
|
||||
let html = this.isHTML ? result : markdown(result)
|
||||
html = formatUpdated(html, opt.updatedAt, this.config.formatUpdated)
|
||||
|
||||
callHook(this, 'afterEach', html, text => renderMain.call(this, text))
|
||||
})
|
||||
}
|
||||
@@ -147,7 +160,7 @@ export function initRender (vm) {
|
||||
const config = vm.config
|
||||
|
||||
// Init markdown compiler
|
||||
markdown.init(config.markdown, config.basePath)
|
||||
markdown.init(config.markdown, config)
|
||||
|
||||
const id = config.el || '#app'
|
||||
const navEl = dom.find('nav') || dom.create('nav')
|
||||
|
||||
Reference in New Issue
Block a user