Skip to content

Commit 2d29d95

Browse files
committed
Use custom edit on github plugin. Fix asdf-vm#469
1 parent d75f02f commit 2d29d95

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",
@@ -62,8 +62,12 @@
6262
},
6363
plugins: [
6464
EditOnGithubPlugin.create(
65-
"https://github.com/asdf-vm/asdf/blob/master/docs/"
66-
),
65+
"https://github.com/asdf-vm/asdf/blob/master/docs/", {
66+
customURLs: {
67+
"https://raw.githubusercontent.com/asdf-vm/asdf-plugins/master/README.md": "https://github.com/asdf-vm/asdf-plugins/edit/master/README.md",
68+
"https://raw.githubusercontent.com/asdf-vm/asdf/master/CHANGELOG.md": "https://github.com/asdf-vm/asdf/edit/master/CHANGELOG.md"
69+
}
70+
})
6771
],
6872
};
6973
</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)