fix: expose version info for Docsify, fixed #641

This commit is contained in:
qingwei.li 2018-11-02 08:53:46 +08:00
parent 22a5927eaf
commit aa719e3a47
3 changed files with 71 additions and 52 deletions

View File

@ -6,41 +6,41 @@ A plugin is simply a function that takes `hook` as an argument. The hook support
```js ```js
window.$docsify = { window.$docsify = {
plugins: [ plugins: [
function (hook, vm) { function(hook, vm) {
hook.init(function() { hook.init(function() {
// Called when the script starts running, only trigger once, no arguments, // Called when the script starts running, only trigger once, no arguments,
}) });
hook.beforeEach(function(content) { hook.beforeEach(function(content) {
// Invoked each time before parsing the Markdown file. // Invoked each time before parsing the Markdown file.
// ... // ...
return content return content;
}) });
hook.afterEach(function(html, next) { hook.afterEach(function(html, next) {
// Invoked each time after the Markdown file is parsed. // Invoked each time after the Markdown file is parsed.
// beforeEach and afterEach support asynchronous。 // beforeEach and afterEach support asynchronous。
// ... // ...
// call `next(html)` when task is done. // call `next(html)` when task is done.
next(html) next(html);
}) });
hook.doneEach(function() { hook.doneEach(function() {
// Invoked each time after the data is fully loaded, no arguments, // Invoked each time after the data is fully loaded, no arguments,
// ... // ...
}) });
hook.mounted(function() { hook.mounted(function() {
// Called after initial completion. Only trigger once, no arguments. // Called after initial completion. Only trigger once, no arguments.
}) });
hook.ready(function() { hook.ready(function() {
// Called after initial completion, no arguments. // Called after initial completion, no arguments.
}) });
} }
] ]
} };
``` ```
!> You can get internal methods through `window.Docsify`. Get the current instance through the second argument. !> 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.
```js ```js
window.$docsify = { window.$docsify = {
plugins: [ plugins: [
function (hook) { function(hook) {
var footer = [ var footer = [
'<hr/>', '<hr/>',
'<footer>', '<footer>',
'<span><a href="https://github.com/QingWei-Li">cinwell</a> &copy;2017.</span>', '<span><a href="https://github.com/QingWei-Li">cinwell</a> &copy;2017.</span>',
'<span>Proudly published with <a href="https://github.com/docsifyjs/docsify" target="_blank">docsify</a>.</span>', '<span>Proudly published with <a href="https://github.com/docsifyjs/docsify" target="_blank">docsify</a>.</span>',
'</footer>' '</footer>'
].join('') ].join('');
hook.afterEach(function (html) { hook.afterEach(function(html) {
return html + footer return html + footer;
}) });
} }
] ]
} };
``` ```
### Edit Button ### Edit Button
@ -77,17 +77,35 @@ window.$docsify = {
window.$docsify = { window.$docsify = {
plugins: [ plugins: [
function(hook, vm) { function(hook, vm) {
hook.beforeEach(function (html) { hook.beforeEach(function(html) {
var url = 'https://github.com/docsifyjs/docsify/blob/master/docs' + vm.route.file var url =
var editHtml = '[📝 EDIT DOCUMENT](' + url + ')\n' 'https://github.com/docsifyjs/docsify/blob/master/docs' +
vm.route.file;
var editHtml = '[📝 EDIT DOCUMENT](' + url + ')\n';
return editHtml return (
+ html editHtml +
+ '\n----\n' html +
+ 'Last modified {docsify-updated} ' '\n----\n' +
+ editHtml 'Last modified {docsify-updated} ' +
}) editHtml
);
});
} }
] ]
} };
``` ```
## Tips
### Get docsify version
```
console.log(window.Docsify.version)
```
Current version: <span id='tip-version'>loading</span>
<script>
document.getElementById('tip-version').innerText = Docsify.version
</script>

View File

@ -7,7 +7,13 @@ import marked from 'marked'
import prism from 'prismjs' import prism from 'prismjs'
export default function () { export default function () {
window.Docsify = {util, dom, get, slugify} window.Docsify = {
util,
dom,
get,
slugify,
version: '__VERSION__'
}
window.DocsifyCompiler = Compiler window.DocsifyCompiler = Compiler
window.marked = marked window.marked = marked
window.Prism = prism window.Prism = prism

View File

@ -35,11 +35,6 @@ eventMixin(proto)
*/ */
initGlobalAPI() initGlobalAPI()
/**
* Version
*/
Docsify.version = '__VERSION__'
/** /**
* Run Docsify * Run Docsify
*/ */