Skip to content

Commit aa719e3

Browse files
committed
fix: expose version info for Docsify, fixed #641
1 parent 22a5927 commit aa719e3

File tree

3 files changed

+77
-58
lines changed

3 files changed

+77
-58
lines changed

docs/write-a-plugin.md

+70-52
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,41 @@ A plugin is simply a function that takes `hook` as an argument. The hook support
66

77
```js
88
window.$docsify = {
9-
plugins: [
10-
function (hook, vm) {
11-
hook.init(function() {
12-
// Called when the script starts running, only trigger once, no arguments,
13-
})
14-
15-
hook.beforeEach(function(content) {
16-
// Invoked each time before parsing the Markdown file.
17-
// ...
18-
return content
19-
})
20-
21-
hook.afterEach(function(html, next) {
22-
// Invoked each time after the Markdown file is parsed.
23-
// beforeEach and afterEach support asynchronous。
24-
// ...
25-
// call `next(html)` when task is done.
26-
next(html)
27-
})
28-
29-
hook.doneEach(function() {
30-
// Invoked each time after the data is fully loaded, no arguments,
31-
// ...
32-
})
33-
34-
hook.mounted(function() {
35-
// Called after initial completion. Only trigger once, no arguments.
36-
})
37-
38-
hook.ready(function() {
39-
// Called after initial completion, no arguments.
40-
})
41-
}
42-
]
43-
}
9+
plugins: [
10+
function(hook, vm) {
11+
hook.init(function() {
12+
// Called when the script starts running, only trigger once, no arguments,
13+
});
14+
15+
hook.beforeEach(function(content) {
16+
// Invoked each time before parsing the Markdown file.
17+
// ...
18+
return content;
19+
});
20+
21+
hook.afterEach(function(html, next) {
22+
// Invoked each time after the Markdown file is parsed.
23+
// beforeEach and afterEach support asynchronous。
24+
// ...
25+
// call `next(html)` when task is done.
26+
next(html);
27+
});
28+
29+
hook.doneEach(function() {
30+
// Invoked each time after the data is fully loaded, no arguments,
31+
// ...
32+
});
33+
34+
hook.mounted(function() {
35+
// Called after initial completion. Only trigger once, no arguments.
36+
});
37+
38+
hook.ready(function() {
39+
// Called after initial completion, no arguments.
40+
});
41+
}
42+
]
43+
};
4444
```
4545

4646
!> You can get internal methods through `window.Docsify`. Get the current instance through the second argument.
@@ -54,21 +54,21 @@ Add footer component in each pages.
5454
```js
5555
window.$docsify = {
5656
plugins: [
57-
function (hook) {
57+
function(hook) {
5858
var footer = [
5959
'<hr/>',
6060
'<footer>',
6161
'<span><a href="https://github.com/QingWei-Li">cinwell</a> &copy;2017.</span>',
6262
'<span>Proudly published with <a href="https://github.com/docsifyjs/docsify" target="_blank">docsify</a>.</span>',
6363
'</footer>'
64-
].join('')
64+
].join('');
6565

66-
hook.afterEach(function (html) {
67-
return html + footer
68-
})
66+
hook.afterEach(function(html) {
67+
return html + footer;
68+
});
6969
}
7070
]
71-
}
71+
};
7272
```
7373

7474
### Edit Button
@@ -77,17 +77,35 @@ window.$docsify = {
7777
window.$docsify = {
7878
plugins: [
7979
function(hook, vm) {
80-
hook.beforeEach(function (html) {
81-
var url = 'https://github.com/docsifyjs/docsify/blob/master/docs' + vm.route.file
82-
var editHtml = '[📝 EDIT DOCUMENT](' + url + ')\n'
83-
84-
return editHtml
85-
+ html
86-
+ '\n----\n'
87-
+ 'Last modified {docsify-updated} '
88-
+ editHtml
89-
})
80+
hook.beforeEach(function(html) {
81+
var url =
82+
'https://github.com/docsifyjs/docsify/blob/master/docs' +
83+
vm.route.file;
84+
var editHtml = '[📝 EDIT DOCUMENT](' + url + ')\n';
85+
86+
return (
87+
editHtml +
88+
html +
89+
'\n----\n' +
90+
'Last modified {docsify-updated} ' +
91+
editHtml
92+
);
93+
});
9094
}
9195
]
92-
}
96+
};
9397
```
98+
99+
## Tips
100+
101+
### Get docsify version
102+
103+
```
104+
console.log(window.Docsify.version)
105+
```
106+
107+
Current version: <span id='tip-version'>loading</span>
108+
109+
<script>
110+
document.getElementById('tip-version').innerText = Docsify.version
111+
</script>

src/core/global-api.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import marked from 'marked'
77
import prism from 'prismjs'
88

99
export default function () {
10-
window.Docsify = {util, dom, get, slugify}
10+
window.Docsify = {
11+
util,
12+
dom,
13+
get,
14+
slugify,
15+
version: '__VERSION__'
16+
}
1117
window.DocsifyCompiler = Compiler
1218
window.marked = marked
1319
window.Prism = prism

src/core/index.js

-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ eventMixin(proto)
3535
*/
3636
initGlobalAPI()
3737

38-
/**
39-
* Version
40-
*/
41-
Docsify.version = '__VERSION__'
42-
4338
/**
4439
* Run Docsify
4540
*/

0 commit comments

Comments
 (0)