From aa719e3a474d6bfb0a66b7c2a93d9317d69e47fc Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Fri, 2 Nov 2018 08:53:46 +0800 Subject: [PATCH] fix: expose version info for Docsify, fixed #641 --- docs/write-a-plugin.md | 122 +++++++++++++++++++++++------------------ src/core/global-api.js | 8 ++- src/core/index.js | 5 -- 3 files changed, 77 insertions(+), 58 deletions(-) diff --git a/docs/write-a-plugin.md b/docs/write-a-plugin.md index 2f5af37f4..d6605d4ed 100644 --- a/docs/write-a-plugin.md +++ b/docs/write-a-plugin.md @@ -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 = [ '
', '' - ].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: loading + + diff --git a/src/core/global-api.js b/src/core/global-api.js index cbe21d7fe..7bdf74c65 100644 --- a/src/core/global-api.js +++ b/src/core/global-api.js @@ -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 diff --git a/src/core/index.js b/src/core/index.js index aee168340..ebb7fe3f2 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -35,11 +35,6 @@ eventMixin(proto) */ initGlobalAPI() -/** - * Version - */ -Docsify.version = '__VERSION__' - /** * Run Docsify */