Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d2be5ae

Browse filesBrowse files
committed
feat: add docsify-updated, close #158
1 parent ca0d618 commit d2be5ae
Copy full SHA for d2be5ae

11 files changed

+95-13Lines changed: 95 additions & 13 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app.js‎

Copy file name to clipboardExpand all lines: app.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var fs = require('fs')
44

55
http.createServer(function (req, res) {
66
serveStatic('.')(req, res, function () {
7-
res.writeHead(404, { 'Content-Type': 'text/html' })
7+
res.writeHead(200, { 'Content-Type': 'text/html' })
88
res.end(fs.readFileSync('dev.html'))
99
})
1010
}).listen(3000, '0.0.0.0')
Collapse file

‎dev.html‎

Copy file name to clipboardExpand all lines: dev.html
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@
3030
loadSidebar: true,
3131
name: 'docsify',
3232
subMaxLevel: 2,
33-
mergeNavbar: true
33+
mergeNavbar: true,
34+
formatUpdated: '{MM}/{DD} {HH}:{mm}',
35+
plugins: [
36+
function(hook) {
37+
hook.beforeEach(function (html) {
38+
return html += '> Last modified {docsify-updated}'
39+
})
40+
}
41+
]
3442
}
3543
</script>
3644
<script src="/lib/docsify.js"></script>
Collapse file

‎docs/configuration.md‎

Copy file name to clipboardExpand all lines: docs/configuration.md
+15Lines changed: 15 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,18 @@ window.$docsify = {
315315
mergeNavbar: true
316316
}
317317
```
318+
319+
## format-updated
320+
We can display the file update date through **{docsify-updated<span>}</span>** variable. And format it by `formatUpdated`.
321+
See https://github.com/lukeed/tinydate#patterns
322+
```js
323+
window.$docsify = {
324+
formatUpdated: '{MM}/{DD} {HH}:{mm}',
325+
326+
formatUpdated: function (time) {
327+
// ...
328+
329+
return time
330+
}
331+
}
332+
```
Collapse file

‎docs/de-de/configuration.md‎

Copy file name to clipboardExpand all lines: docs/de-de/configuration.md
+16-1Lines changed: 16 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,19 @@ Navbar will be merged with the sidebar on smaller screens.
314314
window.$docsify = {
315315
mergeNavbar: true
316316
}
317-
```
317+
```
318+
319+
## format-updated
320+
We can display the file update date through **{docsify-updated<span>}</span>** variable. And format it by `formatUpdated`.
321+
See https://github.com/lukeed/tinydate#patterns
322+
```js
323+
window.$docsify = {
324+
formatUpdated: '{MM}/{DD} {HH}:{mm}',
325+
326+
formatUpdated: function (time) {
327+
// ...
328+
329+
return time
330+
}
331+
}
332+
```
Collapse file

‎docs/index.html‎

Copy file name to clipboardExpand all lines: docs/index.html
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
loadNavbar: true,
3535
mergeNavbar: true,
3636
maxLevel: 4,
37+
subMaxLevel: 2,
3738
name: 'docsify',
3839
search: {
3940
noData: {
@@ -48,7 +49,14 @@
4849
'/': 'Search'
4950
}
5051
},
51-
subMaxLevel: 2
52+
formatUpdated: '{MM}/{DD} {HH}:{mm}',
53+
plugins: [
54+
function(hook) {
55+
hook.beforeEach(function (html) {
56+
return html += '> Last modified {docsify-updated}'
57+
})
58+
}
59+
]
5260
}
5361
</script>
5462
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
Collapse file

‎docs/zh-cn/configuration.md‎

Copy file name to clipboardExpand all lines: docs/zh-cn/configuration.md
+14Lines changed: 14 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,17 @@ window.$docsify = {
326326
}
327327
```
328328

329+
## format-updated
330+
我们可以显示文档更新日期通过 **{docsify-updated<span>}</span>** 变量. 并且格式化日期通过 `formatUpdated`.
331+
参考 https://github.com/lukeed/tinydate#patterns
332+
```js
333+
window.$docsify = {
334+
formatUpdated: '{MM}/{DD} {HH}:{mm}',
335+
336+
formatUpdated: function (time) {
337+
// ...
338+
339+
return time
340+
}
341+
}
342+
```
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"dependencies": {
2929
"marked": "^0.3.6",
3030
"prismjs": "^1.6.0",
31+
"tinydate": "^1.0.0",
3132
"zoom-image": "^0.1.4"
3233
},
3334
"devDependencies": {
Collapse file

‎src/core/config.js‎

Copy file name to clipboardExpand all lines: src/core/config.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const config = merge({
1818
executeScript: null,
1919
noEmoji: false,
2020
ga: '',
21-
mergeNavbar: false
21+
mergeNavbar: false,
22+
formatUpdated: ''
2223
}, window.$docsify)
2324

2425
const script = document.currentScript ||
Collapse file

‎src/core/fetch/ajax.js‎

Copy file name to clipboardExpand all lines: src/core/fetch/ajax.js
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ export function get (url, hasBar = false) {
1414
const on = function () {
1515
xhr.addEventListener.apply(xhr, arguments)
1616
}
17+
const cached = cache[url]
1718

18-
if (cache[url]) {
19-
return { then: cb => cb(cache[url]), abort: noop }
19+
if (cached) {
20+
return { then: cb => cb(cached.content, cached.opt), abort: noop }
2021
}
2122

2223
xhr.open('GET', url)
@@ -41,8 +42,14 @@ export function get (url, hasBar = false) {
4142
if (target.status >= 400) {
4243
error(target)
4344
} else {
44-
cache[url] = target.response
45-
success(target.response)
45+
const result = cache[url] = {
46+
content: target.response,
47+
opt: {
48+
updatedAt: xhr.getResponseHeader('last-modified')
49+
}
50+
}
51+
52+
success(result.content, result.opt)
4653
}
4754
})
4855
},
Collapse file

‎src/core/fetch/index.js‎

Copy file name to clipboardExpand all lines: src/core/fetch/index.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export function fetchMixin (proto) {
2828
this.isHTML = /\.html$/g.test(path)
2929

3030
// Load main content
31-
last.then(text => {
32-
this._renderMain(text)
31+
last.then((text, opt) => {
32+
this._renderMain(text, opt)
3333
if (!loadSidebar) return cb()
3434

3535
const fn = result => { this._renderSidebar(result); cb() }

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.