fix: expose version info for Docsify, fixed #641

fix/351
qingwei.li 6 years ago
parent 22a5927eaf
commit aa719e3a47
  1. 122
      docs/write-a-plugin.md
  2. 8
      src/core/global-api.js
  3. 5
      src/core/index.js

@ -6,41 +6,41 @@ A plugin is simply a function that takes `hook` as an argument. The hook support
```js
window.$docsify = {
plugins: [
function (hook, vm) {
hook.init(function() {
// Called when the script starts running, only trigger once, no arguments,
})
hook.beforeEach(function(content) {
// Invoked each time before parsing the Markdown file.
// ...
return content
})
hook.afterEach(function(html, next) {
// Invoked each time after the Markdown file is parsed.
// beforeEach and afterEach support asynchronous。
// ...
// call `next(html)` when task is done.
next(html)
})
hook.doneEach(function() {
// Invoked each time after the data is fully loaded, no arguments,
// ...
})
hook.mounted(function() {
// Called after initial completion. Only trigger once, no arguments.
})
hook.ready(function() {
// Called after initial completion, no arguments.
})
}
]
}
plugins: [
function(hook, vm) {
hook.init(function() {
// Called when the script starts running, only trigger once, no arguments,
});
hook.beforeEach(function(content) {
// Invoked each time before parsing the Markdown file.
// ...
return content;
});
hook.afterEach(function(html, next) {
// Invoked each time after the Markdown file is parsed.
// beforeEach and afterEach support asynchronous。
// ...
// call `next(html)` when task is done.
next(html);
});
hook.doneEach(function() {
// Invoked each time after the data is fully loaded, no arguments,
// ...
});
hook.mounted(function() {
// Called after initial completion. Only trigger once, no arguments.
});
hook.ready(function() {
// Called after initial completion, no arguments.
});
}
]
};
```
!> 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
window.$docsify = {
plugins: [
function (hook) {
function(hook) {
var footer = [
'<hr/>',
'<footer>',
'<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>',
'</footer>'
].join('')
].join('');
hook.afterEach(function (html) {
return html + footer
})
hook.afterEach(function(html) {
return html + footer;
});
}
]
}
};
```
### Edit Button
@ -77,17 +77,35 @@ window.$docsify = {
window.$docsify = {
plugins: [
function(hook, vm) {
hook.beforeEach(function (html) {
var url = 'https://github.com/docsifyjs/docsify/blob/master/docs' + vm.route.file
var editHtml = '[📝 EDIT DOCUMENT](' + url + ')\n'
return editHtml
+ html
+ '\n----\n'
+ 'Last modified {docsify-updated} '
+ editHtml
})
hook.beforeEach(function(html) {
var url =
'https://github.com/docsifyjs/docsify/blob/master/docs' +
vm.route.file;
var editHtml = '[📝 EDIT DOCUMENT](' + url + ')\n';
return (
editHtml +
html +
'\n----\n' +
'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>

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

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

Loading…
Cancel
Save