From 894c709b3c3d2219664bd91f84c3099026b22d5b Mon Sep 17 00:00:00 2001 From: eallion Date: Sat, 28 Dec 2019 13:17:57 +0800 Subject: [PATCH] add disqus.js --- _config.yml | 18 ++++++++++++------ layout/includes/comments/disqus.pug | 23 ++++++++++------------- layout/includes/comments/disqusjs.pug | 16 ++++++++++++++++ layout/includes/comments/index.pug | 5 ++++- 4 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 layout/includes/comments/disqusjs.pug diff --git a/_config.yml b/_config.yml index 56f4ccd..1330538 100644 --- a/_config.yml +++ b/_config.yml @@ -178,16 +178,22 @@ addtoany: #### Comments System #### # ------------------------------------ - -# Disqus.js 版评论系统,应对大陆长城的折中方案,兼容原版:https://github.com/SukkaW/DisqusJS -# API 申请地址:https://disqus.com/api/applications/ +# Disqus 官方版評論系統 disqus: - enable: false #开启改为 true + enable: false + shortname: + count: false # top_img顯示評論數 + +# Disqus.js 版評論系統,應對大陸長城的折中方案,兼容原版:https://github.com/SukkaW/DisqusJS +# API 申請地址:https://disqus.com/api/applications/ +# 與 disqus 共用樣式 +disqusjs: + enable: false #開啓改爲 true shortname: siteName: apikey: - api: https://disqus.skk.moe/disqus/ #一般情况无需要修改 - count: true # top_img顯示評論數 + api: https://disqus.skk.moe/disqus/ #一般情況下無需修改 API 地址 + count: false # top_img顯示評論數 laibili: enable: false diff --git a/layout/includes/comments/disqus.pug b/layout/includes/comments/disqus.pug index b53f95a..1e0c01c 100644 --- a/layout/includes/comments/disqus.pug +++ b/layout/includes/comments/disqus.pug @@ -1,16 +1,13 @@ if theme.disqus && theme.disqus.enable #disqus_thread - link(href=('https://cdn.jsdelivr.net/npm/disqusjs@1.2/dist/disqusjs.css') rel='stylesheet') - script(src=('https://cdn.jsdelivr.net/npm/disqusjs@1.2/dist/disqus.js')) script. - var dsqjs = new DisqusJS({ - shortname: '!{theme.disqus.shortname}', - siteName: "!{theme.disqus.siteName}", - identifier: '!{ page.path }', - url: '!{ page.permalink }', - title: '!{ page.title }', - api: '!{theme.disqus.api}', - apikey: '!{theme.disqus.apikey}', - admin: '', - adminLabel: '' - }); \ No newline at end of file + var unused = null; + var disqus_config = function () { + this.page.url = '!{ page.permalink }'; + this.page.identifier = '!{ page.path }'; + this.page.title = '!{ page.title }'; + } + var d = document, s = d.createElement('script'); + s.src = "https://" + '!{theme.disqus.shortname}' +".disqus.com/embed.js"; + s.setAttribute('data-timestamp', '' + +new Date()); + (d.head || d.body).appendChild(s); \ No newline at end of file diff --git a/layout/includes/comments/disqusjs.pug b/layout/includes/comments/disqusjs.pug new file mode 100644 index 0000000..aaa7504 --- /dev/null +++ b/layout/includes/comments/disqusjs.pug @@ -0,0 +1,16 @@ +if theme.disqusjs && theme.disqusjs.enable + #disqus_thread + link(href=('https://cdn.jsdelivr.net/npm/disqusjs@1.2/dist/disqusjs.css') rel='stylesheet') + script(src=('https://cdn.jsdelivr.net/npm/disqusjs@1.2/dist/disqus.js')) + script. + var dsqjs = new DisqusJS({ + shortname: '!{theme.disqusjs.shortname}', + siteName: "!{theme.disqusjs.siteName}", + identifier: '!{ page.path }', + url: '!{ page.permalink }', + title: '!{ page.title }', + api: '!{theme.disqusjs.api}', + apikey: '!{theme.disqusjs.apikey}', + admin: '', + adminLabel: '' + }); \ No newline at end of file diff --git a/layout/includes/comments/index.pug b/layout/includes/comments/index.pug index bbc4cd8..ac01ec5 100644 --- a/layout/includes/comments/index.pug +++ b/layout/includes/comments/index.pug @@ -1,9 +1,10 @@ - var d = theme.disqus && theme.disqus.enable +- var dj = theme.disqusjs && theme.disqusjs.enable - var l = theme.laibili && theme.laibili.enable - var gt = theme.gitalk && theme.gitalk.enable - var v = theme.valine && theme.valine.enable -if d || l || gt || v +if d || dj || l || gt || v hr #post-comment .comment_headling @@ -11,6 +12,8 @@ if d || l || gt || v span= ' ' + _p('comment') if d include ./disqus.pug + else if dj + include ./disqusjs.pug else if l include ./laibili.pug else if gt