forked from tasmota/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit-link.js
28 lines (21 loc) · 1009 Bytes
/
edit-link.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function normalizeGithubUrl(url) {
if (!url) { return null }
var isAlias = !/\/\//.test(url) // no protocol in the url, we assume it's an alias
url = isAlias
? 'https://github.com/' + url + '/edit/master/docs/'
: url.replace(/^git\+/, '')
return url
}
function install(hook, vm) {
var editLinkConfig = vm.config.editLink || {}
var text = editLinkConfig.text || 'Edit this page'
var cssClass = editLinkConfig.cssClass || 'edit-link'
var repoUrl = normalizeGithubUrl(editLinkConfig.repo || vm.config.repo)
if (!repoUrl) { throw Error('$docsify.editLink.repo is required. Fix your config.') }
hook.afterEach(function (html) {
var editLink = '<span style="text-align: right; color:#1FA3EC; font-size:80%">' +
'<a href="' + repoUrl + vm.route.file + '" target="_blank" style="text-decoration: none;">' + text + '</a></span>'
return editLink + html
});
}
$docsify.plugins = [].concat(install, $docsify.plugins)