diff --git a/_config.yml b/_config.yml index c8d391a..b97c9f2 100644 --- a/_config.yml +++ b/_config.yml @@ -194,6 +194,15 @@ reward: # - img: /img/alipay.jpg # link: # text: alipay + +# Post edit +# Easily browse and edit blog source code online. +post_edit: + enable: false + # Link for view source + # url: https://github.com/user-name/repo-name/tree/branch-name/subdirectory-name/ + # Link for fork & edit + # url: https://github.com/user-name/repo-name/edit/branch-name/subdirectory-name/ # Related Articles related_post: diff --git a/languages/default.yml b/languages/default.yml index 97bc87f..5dcb02e 100644 --- a/languages/default.yml +++ b/languages/default.yml @@ -30,6 +30,7 @@ post: copyright_notice: Copyright Notice copyright_content: 'All articles in this blog are licensed under %s unless stating additionally.' recommend: Related Articles + edit: Edited on search: Search algolia_search: diff --git a/languages/en.yml b/languages/en.yml index c43506f..92152dd 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -30,6 +30,7 @@ post: copyright_notice: Copyright Notice copyright_content: 'All articles in this blog are licensed under %s unless stating additionally.' recommend: Related Articles + edit: Edited on search: Search algolia_search: diff --git a/languages/zh-CN.yml b/languages/zh-CN.yml index e851e8c..f9f77b5 100644 --- a/languages/zh-CN.yml +++ b/languages/zh-CN.yml @@ -31,6 +31,7 @@ post: copyright_content: '本博客所有文章除特别声明外,均采用 %s 许可协议。转载请注明来自 %s!' recommend: 相关推荐 + edit: 编辑 search: 搜索 algolia_search: diff --git a/languages/zh-TW.yml b/languages/zh-TW.yml index 0b9acc1..1c078a2 100644 --- a/languages/zh-TW.yml +++ b/languages/zh-TW.yml @@ -31,6 +31,7 @@ post: copyright_content: '本部落格所有文章除特別聲明外,均採用 %s 許可協議。轉載請註明來自 %s!' recommend: 相關推薦 + edit: 編輯 search: 搜尋 algolia_search: diff --git a/layout/includes/header/index.pug b/layout/includes/header/index.pug index 4efb3f9..8e4ccf3 100644 --- a/layout/includes/header/index.pug +++ b/layout/includes/header/index.pug @@ -48,3 +48,6 @@ header#page-header(class=isHomeClass style=bg_img) else #page-site-info h1#site-title=site_title + if theme.post_edit.enable + a.post-edit-link(href=post_edit(page.source) title=_p('post.edit')) + i.fa.fa-pen-nib diff --git a/layout/includes/header/post-info.pug b/layout/includes/header/post-info.pug index 9639512..96ca6be 100644 --- a/layout/includes/header/post-info.pug +++ b/layout/includes/header/post-info.pug @@ -1,6 +1,9 @@ #post-info h1.post-title= page.title || _p('no_title') - + if theme.post_edit.enable + a.post-edit-link(href=post_edit(page.source) title=_p('post.edit')) + i.fa.fa-pen-nib + #post-meta .meta-firstline if (theme.post_meta.post.date_type) diff --git a/scripts/helpers/page.js b/scripts/helpers/page.js index fd44158..d9274fb 100644 --- a/scripts/helpers/page.js +++ b/scripts/helpers/page.js @@ -70,3 +70,9 @@ hexo.extend.helper.register('injectHtml', function (data) { } return result }) + +hexo.extend.helper.register('post_edit', function(src) { + const { post_edit } = this.theme; + if (!post_edit.enable) return ''; + return post_edit.url + src +}) \ No newline at end of file diff --git a/source/css/_layout/head.styl b/source/css/_layout/head.styl index b081f93..1c737de 100644 --- a/source/css/_layout/head.styl +++ b/source/css/_layout/head.styl @@ -84,6 +84,9 @@ +maxWidth768() top: 7rem + .post-edit-link + padding-left: 0.3rem + // post &.post-bg height: 20rem @@ -141,6 +144,9 @@ +maxWidth768() font-size: 1.72em + + .post-edit-link + padding-left: 0.3rem #post-meta color: var(--light-grey) @@ -193,6 +199,9 @@ border-bottom: 1px solid var(--light-grey) color: var(--text-highlight-color) + .post-edit-link + float: right + #post-meta, #post-meta a color: #78818a