feat: add Edit on GitHub button for pages

添加“在 GitHub 编辑”按钮
This commit is contained in:
yanglbme 2020-05-06 20:37:40 +08:00
parent 36e13c9496
commit 9e50672429
2 changed files with 20 additions and 9 deletions

View File

@ -186,7 +186,6 @@
GitHub 技术社区 [Doocs](https://github.com/doocs) 旗下唯一公众号「**Doocs开源社区**」​,欢迎扫码关注,**专注分享技术领域相关知识及行业最新资讯**。当然也可以加我个人微信备注GitHub拉你进技术交流群。
<table>
<tr>
<td align="center" style="width: 200px;">
<a href="https://github.com/doocs">
@ -201,5 +200,4 @@ GitHub 技术社区 [Doocs](https://github.com/doocs) 旗下唯一公众号「**
</a><br>
</td>
</tr>
</table>

View File

@ -72,15 +72,28 @@
}
},
plugins: [
function (hook) {
var footer = [
'<hr/>',
'<footer>',
'<span>Copyright © 2018-2020 <a href="https://github.com/doocs" target="_blank">Doocs</a>. All rights reserved.',
'</footer>'
].join('')
function (hook, vm) {
hook.beforeEach(function (html) {
const en = vm.route.file.indexOf('README_EN') > -1
if (/githubusercontent\.com/.test(vm.route.file)) {
url = vm.route.file
.replace('raw.githubusercontent.com', 'github.com')
.replace(/\/master/, '/blob/master')
} else {
url = 'https://github.com/doocs/advanced-java/blob/master/' + vm.route.file
}
const edit = en ? 'Edit on GitHub' : ' GitHub 编辑'
const editHtml = `[:memo: ${edit}](${url})\n`
return editHtml + html
})
hook.afterEach(function (html) {
const footer = [
'<hr/>',
'<footer>',
'<span>Copyright © 2018-2020 <a href="https://github.com/doocs" target="_blank">Doocs</a>. All rights reserved.',
'</footer>'
].join('')
return html + footer
})
}