Skip to content

Commit 5a89e48

Browse files
authored
Merge pull request asdf-vm#495 from asdf-vm/fix-edit-on-github
Use custom edit on github plugin. Fix asdf-vm#469
2 parents 021e843 + 2d29d95 commit 5a89e48

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

docs/index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<body>
2525
<div id="app"></div>
2626
<!-- edit on github plugin must appear here -->
27-
<script src="//unpkg.com/docsify-edit-on-github@1.0.1/index.js"></script>
27+
<script src="scripts/docsify-edit-on-github.js"></script>
2828
<script>
2929
window.$docsify = {
3030
name: "asdf-vm",
@@ -61,8 +61,12 @@
6161
},
6262
plugins: [
6363
EditOnGithubPlugin.create(
64-
"https://github.com/asdf-vm/asdf/blob/master/docs/"
65-
),
64+
"https://github.com/asdf-vm/asdf/blob/master/docs/", {
65+
customURLs: {
66+
"https://raw.githubusercontent.com/asdf-vm/asdf-plugins/master/README.md": "https://github.com/asdf-vm/asdf-plugins/edit/master/README.md",
67+
"https://raw.githubusercontent.com/asdf-vm/asdf/master/CHANGELOG.md": "https://github.com/asdf-vm/asdf/edit/master/CHANGELOG.md"
68+
}
69+
})
6670
],
6771
};
6872
</script>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
;(function(win) {
2+
win.EditOnGithubPlugin = {}
3+
4+
function create(docBase, options) {
5+
options = options || {}
6+
title = options.title || 'Edit on github'
7+
customURLs = options.customURLs || {}
8+
var docEditBase = docBase.replace(/\/blob\//, '/edit/')
9+
10+
function editDoc(event, vm) {
11+
var docName = vm.route.file
12+
13+
if (docName) {
14+
var editLink = customURLs[docName] || docEditBase + docName
15+
window.open(editLink)
16+
event.preventDefault()
17+
return false
18+
} else {
19+
return true
20+
}
21+
}
22+
23+
win.EditOnGithubPlugin.editDoc = editDoc
24+
25+
return function(hook, vm) {
26+
win.EditOnGithubPlugin.onClick = function(event) {
27+
EditOnGithubPlugin.editDoc(event, vm)
28+
}
29+
30+
var header = [
31+
'<div style="overflow: auto">',
32+
'<p style="float: right"><a href="',
33+
docBase,
34+
'" target="_blank" onclick="EditOnGithubPlugin.onClick(event)">',
35+
title,
36+
'</a></p>',
37+
'</div>'
38+
].join('')
39+
40+
hook.afterEach(function (html) {
41+
return header + html
42+
})
43+
}
44+
}
45+
46+
win.EditOnGithubPlugin.create = create
47+
}) (window)

0 commit comments

Comments
 (0)