├── LICENSE ├── README.md ├── index.html ├── index.js └── package.json /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Leon Zhang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docsify-edit-on-github 2 | A plugin for docsify to generate a `edit on github` button on every pages. click the button to open corresponding `md` editing page on github. 3 | 4 | ```html 5 | 6 | ``` 7 | 8 | ```html 9 | 18 | ``` 19 | 20 | * `docBase`: [String] the document folder of your github project (e.g.: https://github.com/docsifyjs/docsify/blob/master/docs/) 21 | * `docEditBase`: [String] edit link of your github pages, by default, this is set automatically according to `docBase` 22 | * `title`: [String | Function] the text of the button, default value: `Edit on github`. If passed as function, then the title can be customized according to file path. for example: 23 | ``` 24 | EditOnGithubPlugin.create( 25 | 'https://github.com/docsifyjs/docsify/blob/master/docs/', 26 | null, 27 | function(file) { 28 | if (file.indexOf('en') === -1) { 29 | return '编辑' 30 | } else { 31 | return 'edit on git' 32 | } 33 | } 34 | ) 35 | ``` 36 | 37 | [Code example](https://github.com/njleonzhang/vue-data-tables/blob/6bb632419506a14ceff559708180883097d5afa2/docs/index.html#L179-L181) 38 | 39 | [Result example](https://www.njleonzhang.com/vue-data-tables/#/en-us/basic) 40 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | docsify-edit-on-github - edit on github plugin for docsify 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | ;(function(win) { 2 | function isFunction(functionToCheck) { 3 | return functionToCheck && {}.toString.call(functionToCheck) === '[object Function]' 4 | } 5 | 6 | win.EditOnGithubPlugin = {} 7 | 8 | function create(docBase, docEditBase, title) { 9 | title = title || 'Edit on GitHub' 10 | docEditBase = docEditBase || docBase.replace(/\/blob\//, '/edit/') 11 | 12 | function editDoc(event, vm) { 13 | var docName = vm.route.file 14 | 15 | if (docName) { 16 | var editLink = docEditBase + docName 17 | window.open(editLink) 18 | event.preventDefault() 19 | return false 20 | } else { 21 | return true 22 | } 23 | } 24 | 25 | win.EditOnGithubPlugin.editDoc = editDoc 26 | 27 | function generateHeader(title) { 28 | return header = [ 29 | '
', 30 | '

', 32 | title, 33 | '

', 34 | '
' 35 | ].join('') 36 | } 37 | 38 | return function(hook, vm) { 39 | win.EditOnGithubPlugin.onClick = function(event) { 40 | EditOnGithubPlugin.editDoc(event, vm) 41 | } 42 | 43 | if (isFunction(title)) { 44 | 45 | hook.afterEach(function (html) { 46 | return generateHeader(title(vm.route.file)) + html 47 | }) 48 | } else { 49 | var header = generateHeader(title) 50 | 51 | hook.afterEach(function (html) { 52 | return header + html 53 | }) 54 | } 55 | 56 | 57 | } 58 | } 59 | 60 | win.EditOnGithubPlugin.create = create 61 | }) (window) 62 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docsify-edit-on-github", 3 | "version": "1.0.3", 4 | "description": "edit on github plugin for docsify", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "docsify serve test" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/njleonzhang/docsify-edit-on-github.git" 12 | }, 13 | "author": "", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/njleonzhang/docsify-edit-on-github/issues" 17 | }, 18 | "homepage": "https://github.com/njleonzhang/docsify-edit-on-github#readme" 19 | } 20 | --------------------------------------------------------------------------------