From 43cc5778a754704eaa14d20abe00d4a3510d6445 Mon Sep 17 00:00:00 2001 From: txmu Date: Sun, 29 Nov 2020 23:05:16 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E8=BF=99=E4=B8=A4=E5=A4=A9=E5=8F=91?= =?UTF-8?q?=E7=8E=B0gittalk,gitment=20=E8=BF=99=20=E4=BA=9B=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=96=B9app=E5=AD=98=E5=9C=A8=E5=BE=88=E5=A4=A7?= =?UTF-8?q?=E7=9A=84=E9=A3=8E=E9=99=A9=EF=BC=8C=E5=B0=B1=E9=80=82=E9=85=8D?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=AA=E5=AE=89=E5=85=A8=E9=9A=90=E6=82=A3?= =?UTF-8?q?=E5=B0=8F=E4=B8=80=E7=82=B9=E7=9A=84utterances?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 26 ++++++------- layout/contact.ejs | 92 ++++++++++++++++++++++++---------------------- 2 files changed, 61 insertions(+), 57 deletions(-) diff --git a/_config.yml b/_config.yml index 9c75f7ef2..c43e79487 100644 --- a/_config.yml +++ b/_config.yml @@ -268,20 +268,12 @@ myGallery: # 设置在归档页面中是否显示'文章日历'控件 postCalendar: true -# 不建议使用gittalk,gitment这样权限过高的oauth app,因为它们能够 读写 授权者 所有的公共仓库 ,也就是说拿到你的授权 Token 的人,可以将你的 GitHub 公共仓库删空(这是github权限分的不够细的锅),如果恶意攻击者想获取使用者的 AccessToken,只需要在代码中加上一个 ajax 请求即可。原贴地址:https://www.v2ex.com/t/535608。建议大家看完。(我没有在用gittalk/gitment的网站上评论过,但根据v2ex网友的提示,如果网站自行修改了 gitalk.js 脚本 或者反代了 github api,就很容易拿到你的 Token ) +# (以下注释内容均为txmu编写)不建议使用gittalk,gitment这样权限过高的oauth app,因为它们能够读写授权者(评论者,如果博主回复过评论,那么博主也算) 所有的公共仓库 ,也就是说拿到你的授权 Token 的人,可以将你的 GitHub 公共仓库删空(这是github权限分的不够细的锅),如果恶意攻击者想获取使用者的 AccessToken,只需要在https://github.com/gitalk/gitalk/blob/master/src/gitalk.jsx#L156的代码中加上一个 ajax 请求即可。(我没有在用gittalk/gitment的网站上评论过,但如果网站自行修改了 gitalk.js 脚本 或者反代了 github api,就很容易拿到你的 Token,所以我专门把utterances适配了一下,本地博客实测正常。utterances教程:https://blog.njilc.com/post/self-hosted-utterances-tutorial) -# https://github.com/utterance/utterances 是个 GitHub App,它的权限仅限于某个仓库。像 hugo hexo 这种静态页面类型的博客,clientID/clientSecret 泄露是不可避免的。我认为较好的解决方式是像 utteras 这种 GitHubApp,只有一个仓库的读写权限,将破坏降到最小。 - -# valine和minivaline都是使用的免费的leancloud开发版资源,即使数据丢了leancloud也不用负任何的责任。此外valine的src目录已在1.4.0后停止更新。。。薛定谔的开源。 - -# 当初多说国内最大都倒了,livere不一定靠谱。 - -# disqus被墙了。 - -# 畅言需要备案。 +# 我(txmu)用过的部分评论系统速度排序:minivaline(最快)=utterances(最快)>livere>畅言(我测试的时候是刷新一次后显示) # the Gitalk config,default disabled -# Gitalk 评论模块的配置,默认为不激活 +# Gitalk 评论模块的配置,默认为不激活。目前不建议使用。 gitalk: enable: false owner: @@ -292,7 +284,7 @@ gitalk: admin: # the Gitment config,default disabled -# Gitment 评论模块的配置,默认为不激活 +# Gitment 评论模块的配置,默认为不激活。目前不建议使用。 gitment: enable: false owner: @@ -302,7 +294,7 @@ gitment: clientSecret: # disqus config, default disabled -# Disqus评论模块的配置,默认为不激活 +# Disqus评论模块的配置,默认为不激活。被墙。可以看看DisqusJS。 disqus: enable: false shortname: @@ -376,6 +368,14 @@ changyan: enable: false appId: conf: + +utterances: + enable: true + repo: txmu/utterances + issue-term: pathname # 不能更改,除非你修改了utterances.ejs + theme: github-light + crossorigin: anonymous + # Whether to display fork me on github icon and link, default true, You can change it to your repo address # 配置是否在 header 中显示 fork me on github 的图标,默认为true,你可以修改为你的仓库地址. githubLink: diff --git a/layout/contact.ejs b/layout/contact.ejs index c5ec1ad86..878f19ce3 100755 --- a/layout/contact.ejs +++ b/layout/contact.ejs @@ -1,44 +1,48 @@ -<%- partial('_partial/bg-cover') %> - -
-
-
-
-
-   <%= __('contact') %> -
- <%- page.content %> -
-
-
- <% if (theme.gitalk && theme.gitalk.enable) { %> - <%- partial('_partial/gitalk') %> - <% } %> - - <% if (theme.gitment.enable) { %> - <%- partial('_partial/gitment') %> - <% } %> - - <% if (theme.disqus.enable) { %> - <%- partial('_partial/disqus') %> - <% } %> - - <% if (theme.livere && theme.livere.enable) { %> - <%- partial('_partial/livere') %> - <% } %> - - <% if (theme.valine && theme.valine.enable) { %> - <%- partial('_partial/valine') %> - <% } %> - - <% if (theme.minivaline && theme.minivaline.enable) { %> - <%- partial('_partial/minivaline') %> - <% } %> - - <% if (theme.changyan && theme.changyan.enable) { %> - <%- partial('_partial/changyan') %> - <% } %> - -
-
-
+<%- partial('_partial/bg-cover') %> + +
+
+
+
+
+   <%= __('contact') %> +
+ <%- page.content %> +
+
+
+ <% if (theme.gitalk && theme.gitalk.enable) { %> + <%- partial('_partial/gitalk') %> + <% } %> + + <% if (theme.gitment.enable) { %> + <%- partial('_partial/gitment') %> + <% } %> + + <% if (theme.disqus.enable) { %> + <%- partial('_partial/disqus') %> + <% } %> + + <% if (theme.livere && theme.livere.enable) { %> + <%- partial('_partial/livere') %> + <% } %> + + <% if (theme.valine && theme.valine.enable) { %> + <%- partial('_partial/valine') %> + <% } %> + + <% if (theme.minivaline && theme.minivaline.enable) { %> + <%- partial('_partial/minivaline') %> + <% } %> + + <% if (theme.changyan && theme.changyan.enable) { %> + <%- partial('_partial/changyan') %> + <% } %> + + <% if (theme.utterances && theme.utterances.enable) { %> + <%- partial('_partial/utterances.ejs') %> + <% } %> + +
+
+
From 60288782454926e5f56ca943bc2db6935fb91732 Mon Sep 17 00:00:00 2001 From: txmu Date: Mon, 30 Nov 2020 11:58:24 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index c43e79487..631354fcc 100644 --- a/_config.yml +++ b/_config.yml @@ -270,7 +270,7 @@ postCalendar: true # (以下注释内容均为txmu编写)不建议使用gittalk,gitment这样权限过高的oauth app,因为它们能够读写授权者(评论者,如果博主回复过评论,那么博主也算) 所有的公共仓库 ,也就是说拿到你的授权 Token 的人,可以将你的 GitHub 公共仓库删空(这是github权限分的不够细的锅),如果恶意攻击者想获取使用者的 AccessToken,只需要在https://github.com/gitalk/gitalk/blob/master/src/gitalk.jsx#L156的代码中加上一个 ajax 请求即可。(我没有在用gittalk/gitment的网站上评论过,但如果网站自行修改了 gitalk.js 脚本 或者反代了 github api,就很容易拿到你的 Token,所以我专门把utterances适配了一下,本地博客实测正常。utterances教程:https://blog.njilc.com/post/self-hosted-utterances-tutorial) -# 我(txmu)用过的部分评论系统速度排序:minivaline(最快)=utterances(最快)>livere>畅言(我测试的时候是刷新一次后显示) +# 我(txmu)用过的部分评论系统速度排序:minivaline(最快)=utterances(最快)>Disqus(墙外)>livere>畅言 # the Gitalk config,default disabled # Gitalk 评论模块的配置,默认为不激活。目前不建议使用。 From e9371b49f84e7b77de97085c32fb6db8d8eaa377 Mon Sep 17 00:00:00 2001 From: txmu Date: Mon, 30 Nov 2020 20:05:51 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E9=97=B2=E7=9D=80=E6=B2=A1=E4=BA=8B?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E4=B8=A4=E4=B8=AA=E8=AF=84=E8=AE=BA=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E7=9A=84=E6=94=AF=E6=8C=81=EF=BC=8C=E4=B8=8D=E8=BF=87?= =?UTF-8?q?=E6=88=91=E6=B2=A1=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 23 ++++++++++++++++++++++- layout/contact.ejs | 4 ++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/_config.yml b/_config.yml index 631354fcc..7ee7fb45a 100644 --- a/_config.yml +++ b/_config.yml @@ -372,10 +372,31 @@ changyan: utterances: enable: true repo: txmu/utterances - issue-term: pathname # 不能更改,除非你修改了utterances.ejs theme: github-light crossorigin: anonymous +# DisqusJS +# Alternative Disqus - Render comment component using Disqus API. +# Demo: https://suka.js.org/DisqusJS/ +# For more information: https://github.com/SukkaW/DisqusJS +disqusjs: + enable: false + # API Endpoint of Disqus API (https://disqus.com/api/). + # Leave api empty if you are able to connect to Disqus API. Otherwise you need a reverse proxy for it. + # For example: + # api: https://disqus.skk.moe/disqus/ + api: + apikey: # Register new application from https://disqus.com/api/applications/ + shortname: # See: https://disqus.com/admin/settings/general/ + +# Vssue +# 教程:https://vssue.js.org/zh/,以下配置项必须按照官网的格式填写。有问题第一时间别直接发issue,而是先去自己解决。 +vssue: + enable: false # 由于vssue本身的问题,所有页面所有的评论都可能会关联到以这个title为题目的issue,导致评论混乱。这个问题我(txmu)已经发过issue了,还没有收到回复。因此用不用这个见仁见智。 + owner: + repo: + clientid: + # Whether to display fork me on github icon and link, default true, You can change it to your repo address # 配置是否在 header 中显示 fork me on github 的图标,默认为true,你可以修改为你的仓库地址. githubLink: diff --git a/layout/contact.ejs b/layout/contact.ejs index 878f19ce3..dd4c2e556 100755 --- a/layout/contact.ejs +++ b/layout/contact.ejs @@ -43,6 +43,10 @@ <%- partial('_partial/utterances.ejs') %> <% } %> + <% if (theme.vssue && theme.vssue.enable) { %> + <%- partial('_partial/vssue.ejs') %> + <% } %> + From 4869f0cd4c798bb42e20b2a062003e8e44e1b993 Mon Sep 17 00:00:00 2001 From: txmu Date: Tue, 1 Dec 2020 17:56:28 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8Ddisqusjs=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layout/contact.ejs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/layout/contact.ejs b/layout/contact.ejs index dd4c2e556..de1e4a557 100755 --- a/layout/contact.ejs +++ b/layout/contact.ejs @@ -47,6 +47,10 @@ <%- partial('_partial/vssue.ejs') %> <% } %> + <% if (theme.disqusjs && theme.disqusjs.enable) { %> + <%- partial('_partial/disqusjs/disqusjs.js') %> + <% } %> + From 82f6a2e0cf92537bda715bd4821a2b00125e60e9 Mon Sep 17 00:00:00 2001 From: txmu Date: Wed, 2 Dec 2020 17:25:26 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layout/_partial/disqusjs/disqusjs.js | 22 +++++++++++++ layout/_partial/disqusjs/disqusjs.njk | 18 +++++++++++ layout/_partial/utterances.ejs | 11 +++++++ layout/_partial/vssue.ejs | 45 +++++++++++++++++++++++++++ source/js/disqusjs.js | 22 +++++++++++++ 5 files changed, 118 insertions(+) create mode 100644 layout/_partial/disqusjs/disqusjs.js create mode 100644 layout/_partial/disqusjs/disqusjs.njk create mode 100644 layout/_partial/utterances.ejs create mode 100644 layout/_partial/vssue.ejs create mode 100644 source/js/disqusjs.js diff --git a/layout/_partial/disqusjs/disqusjs.js b/layout/_partial/disqusjs/disqusjs.js new file mode 100644 index 000000000..fda4b187a --- /dev/null +++ b/layout/_partial/disqusjs/disqusjs.js @@ -0,0 +1,22 @@ +/* global hexo */ + +'use strict'; + +const path = require('path'); + +// Add comment +hexo.extend.filter.register('theme_inject', injects => { + const theme = hexo.theme.config; + if (!theme.disqusjs.enable || !theme.disqusjs.shortname || !theme.disqusjs.apikey) return; + + injects.comment.raw('disqusjs', ` +
+
+ +
+
+ `, {}, {cache: true}); + + injects.bodyEnd.file('disqusjs', path.join(hexo.theme_dir, 'layout/_partial/disqusjs/disqusjs.njk')); + +}); diff --git a/layout/_partial/disqusjs/disqusjs.njk b/layout/_partial/disqusjs/disqusjs.njk new file mode 100644 index 000000000..c746cc9c3 --- /dev/null +++ b/layout/_partial/disqusjs/disqusjs.njk @@ -0,0 +1,18 @@ +{%- if page.comments %} + + + +{%- endif %} diff --git a/layout/_partial/utterances.ejs b/layout/_partial/utterances.ejs new file mode 100644 index 000000000..6af248bd6 --- /dev/null +++ b/layout/_partial/utterances.ejs @@ -0,0 +1,11 @@ +<% if (theme.utterances.enable) { %> +
+ +
+<% } %> diff --git a/layout/_partial/vssue.ejs b/layout/_partial/vssue.ejs new file mode 100644 index 000000000..e15fcaf4f --- /dev/null +++ b/layout/_partial/vssue.ejs @@ -0,0 +1,45 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + diff --git a/source/js/disqusjs.js b/source/js/disqusjs.js new file mode 100644 index 000000000..15907387a --- /dev/null +++ b/source/js/disqusjs.js @@ -0,0 +1,22 @@ +/* global hexo */ + +'use strict'; + +const path = require('path'); + +// Add comment +hexo.extend.filter.register('theme_inject', injects => { + const theme = hexo.theme.config; + if (!theme.disqusjs.enable || !theme.disqusjs.shortname || !theme.disqusjs.apikey) return; + + injects.comment.raw('disqusjs', ` +
+
+ +
+
+ `, {}, {cache: true}); + + injects.bodyEnd.file('disqusjs', path.join(hexo.theme_dir, 'layout/_third-party/comments/disqusjs.njk')); + +});