Use custom edit on github plugin. Fix #469

This commit is contained in:
Daniel Perez 2019-03-24 14:30:53 +00:00
parent d75f02fc29
commit 2d29d9534c
2 changed files with 54 additions and 3 deletions

View File

@ -24,7 +24,7 @@
<body>
<div id="app"></div>
<!-- edit on github plugin must appear here -->
<script src="//unpkg.com/docsify-edit-on-github@1.0.1/index.js"></script>
<script src="scripts/docsify-edit-on-github.js"></script>
<script>
window.$docsify = {
name: "asdf-vm",
@ -62,8 +62,12 @@
},
plugins: [
EditOnGithubPlugin.create(
"https://github.com/asdf-vm/asdf/blob/master/docs/"
),
"https://github.com/asdf-vm/asdf/blob/master/docs/", {
customURLs: {
"https://raw.githubusercontent.com/asdf-vm/asdf-plugins/master/README.md": "https://github.com/asdf-vm/asdf-plugins/edit/master/README.md",
"https://raw.githubusercontent.com/asdf-vm/asdf/master/CHANGELOG.md": "https://github.com/asdf-vm/asdf/edit/master/CHANGELOG.md"
}
})
],
};
</script>

View File

@ -0,0 +1,47 @@
;(function(win) {
win.EditOnGithubPlugin = {}
function create(docBase, options) {
options = options || {}
title = options.title || 'Edit on github'
customURLs = options.customURLs || {}
var docEditBase = docBase.replace(/\/blob\//, '/edit/')
function editDoc(event, vm) {
var docName = vm.route.file
if (docName) {
var editLink = customURLs[docName] || docEditBase + docName
window.open(editLink)
event.preventDefault()
return false
} else {
return true
}
}
win.EditOnGithubPlugin.editDoc = editDoc
return function(hook, vm) {
win.EditOnGithubPlugin.onClick = function(event) {
EditOnGithubPlugin.editDoc(event, vm)
}
var header = [
'<div style="overflow: auto">',
'<p style="float: right"><a href="',
docBase,
'" target="_blank" onclick="EditOnGithubPlugin.onClick(event)">',
title,
'</a></p>',
'</div>'
].join('')
hook.afterEach(function (html) {
return header + html
})
}
}
win.EditOnGithubPlugin.create = create
}) (window)