Skip to content

Commit

Permalink
fix: expose version info for Docsify, fixed #641
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Nov 2, 2018
1 parent 22a5927 commit aa719e3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 58 deletions.
122 changes: 70 additions & 52 deletions docs/write-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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>
8 changes: 7 additions & 1 deletion src/core/global-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ eventMixin(proto)
*/
initGlobalAPI()

/**
* Version
*/
Docsify.version = '__VERSION__'

/**
* Run Docsify
*/
Expand Down

1 comment on commit aa719e3

@jhildenbiddle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 😄

Please sign in to comment.