diff --git a/_config.yml b/_config.yml index a81e467fa5..734f639d93 100644 --- a/_config.yml +++ b/_config.yml @@ -597,20 +597,28 @@ calendar: # --------------------------------------------------------------- # Comments and Widgets # See: https://theme-next.org/docs/third-party-services/comments-and-widgets +# You can set one type to enable. +# And need to provide additional configurations are required for those types. +# Note: facebook_comments_plugin and vkontakte have to enable SDK. # --------------------------------------------------------------- +comments: + # Type list: + # disqus | disqusjs | changyan | valine | livere | gitment | gitalk | facebook_comments_plugin | vkontakte + type: + # If comment system support, show comments count in meta area + count: + page: true + post: true # Disqus disqus: - enable: false shortname: - count: true lazyload: false # DisqusJS # Alternative Disqus - Render comment component using Disqus API # Demo: https://suka.js.org/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 Disqus API @@ -622,15 +630,14 @@ disqusjs: # Changyan changyan: - enable: false appid: appkey: # Valine # You can get your appid and appkey from https://leancloud.cn # More info available at https://valine.js.org +# When comments.type is set to valine, leancloud_visitors is recommended to be closed for the re-initialization problem within different leancloud adk version. valine: - enable: false # When enable is set to be true, leancloud_visitors is recommended to be closed for the re-initialization problem within different leancloud adk version. appid: # your leancloud application appid appkey: # your leancloud application appkey notify: false # mail notifier, See: https://github.com/xCss/Valine/wiki @@ -641,7 +648,6 @@ valine: pageSize: 10 # pagination size language: # language, available values: en, zh-cn visitor: false # leancloud-counter-security is not supported for now. When visitor is set to be true, appid and appkey are recommended to be the same as leancloud_visitors' for counter compatibility. Article reading statistic https://valine.js.org/visitor.html - comment_count: true # if false, comment count will only be displayed in post page, not in home page # LiveRe comments system # You can get your uid from https://livere.com/insight/myCode (General web site) @@ -650,9 +656,7 @@ valine: # Gitment # Introduction: https://github.com/imsun/gitment gitment: - enable: false mint: true # RECOMMEND, A mint on Gitment, to support count, language and proxy_gateway - count: true # Show comments count in post meta area lazy: false # Comments lazy loading with a button cleanly: false # Hide 'Powered by ...' on footer, and more language: # Force language, or auto switch by theme @@ -666,7 +670,6 @@ gitment: # Gitalk # Demo: https://gitalk.github.io gitalk: - enable: false github_id: # Github repo owner repo: # Repository name to store issues client_id: # Github Application Client ID @@ -776,7 +779,6 @@ facebook_sdk: # This plugin depends on Facebook SDK. # If facebook_sdk.enable is false, Facebook comments plugin is unavailable. facebook_comments_plugin: - enable: false num_of_posts: 10 # min posts num is 1 width: 100% # default width is 550px scheme: light # default scheme is light (light or dark) @@ -787,7 +789,6 @@ vkontakte_api: enable: false app_id: # like: true - comments: true num_of_posts: 10 # Star rating support to each article. diff --git a/layout/_macro/post.swig b/layout/_macro/post.swig index c61ee8c121..dfeb424c91 100644 --- a/layout/_macro/post.swig +++ b/layout/_macro/post.swig @@ -139,54 +139,11 @@ {% endif %} {% if post.comments %} - {% macro comments() %} - - - - {% endmacro %} - {% if theme.facebook_comments_plugin.enable %} - {{ comments() }} - - - 0 - - - {% elif theme.disqus.enable and theme.disqus.count %} - {{ comments() }} - {{ __('post.comments_count') + __('symbol.colon') }} - - - - - {% elif theme.changyan.enable and theme.changyan.appid and theme.changyan.appkey %} - {{ comments() }} - {% if is_post() %} - {{ __('post.comments_count') + __('symbol.colon') }} - - - - {% else %} - {{ __('post.comments_count') + __('symbol.colon') }} - - - - {% endif %} - {% elif is_post() and theme.gitment.enable and theme.gitment.mint and theme.gitment.count %} - {{ comments() }} - {{ __('post.comments_count') + __('symbol.colon') }} - - - - - {% elif (is_post() or theme.valine.comment_count) and theme.valine.enable and theme.valine.appid and theme.valine.appkey %} - {{ comments() }} - {{ __('post.comments_count') + __('symbol.colon') }} - - - - + {% set comments_count_post_enable = is_post() and theme.comments.count.post %} + {% set comments_count_page_enable = not is_post() and theme.comments.count.page %} + {% if theme.comments.type and (comments_count_post_enable or comments_count_page_enable) %} + {% set comments_count_path = '_third-party/comments/' + theme.comments.type|lower + '/count.swig' %} + {{ partial(comments_count_path,{ post: post }) }} {% endif %} {% endif %} diff --git a/layout/_partials/comments.swig b/layout/_partials/comments.swig index 8c16ef8998..342e487054 100644 --- a/layout/_partials/comments.swig +++ b/layout/_partials/comments.swig @@ -1,57 +1,6 @@ {% if page.comments %} - - {% if theme.facebook_sdk.enable and theme.facebook_comments_plugin.enable %} -
-
-
-
- - {% elif theme.vkontakte_api.enable and theme.vkontakte_api.comments %} -
-
-
- - {% elif theme.disqus.enable or (theme.disqusjs.enable and theme.disqusjs.apikey and theme.disqusjs.shortname) %} -
-
- -
-
- - {% elif theme.livere_uid %} -
-
-
- - {% elif theme.changyan.enable and theme.changyan.appid and theme.changyan.appkey %} -
-
-
- - {% elif theme.gitment.enable %} -
- {% if theme.gitment.lazy %} -
{{ __('gitmentbutton') }}
- - {% else %} -
- {% endif %} -
- - {% elif theme.valine.enable and theme.valine.appid and theme.valine.appkey %} -
-
- - {% elif theme.gitalk.enable %} -
-
- + {% if theme.comments.type %} + {% set comments_comment_path = '_third-party/comments/' + theme.comments.type|lower + '/comment.swig' %} + {{ partial(comments_comment_path) }} {% endif %} - {% endif %} diff --git a/layout/_third-party/analytics/vkontakte-api.swig b/layout/_third-party/analytics/vkontakte-api.swig index 4ed0c624a6..3c3318b435 100644 --- a/layout/_third-party/analytics/vkontakte-api.swig +++ b/layout/_third-party/analytics/vkontakte-api.swig @@ -10,7 +10,7 @@ VK.Widgets.Like("vk_like", {type: "mini", height: 20}); {% endif %} - {% if page.comments and theme.vkontakte_api.comments %} + {% if page.comments and theme.comments.type|lower === 'vkontakte' %} VK.Widgets.Comments("vk_comments", {limit: {{ theme.vkontakte_api.num_of_posts }}, attach: "*"}); {% endif %} }; diff --git a/layout/_third-party/comments/changyan/comment.swig b/layout/_third-party/comments/changyan/comment.swig new file mode 100644 index 0000000000..39a87eb290 --- /dev/null +++ b/layout/_third-party/comments/changyan/comment.swig @@ -0,0 +1,5 @@ +{% if theme.changyan.appid and theme.changyan.appkey %} +
+
+
+{% endif %} \ No newline at end of file diff --git a/layout/_third-party/comments/changyan/count.swig b/layout/_third-party/comments/changyan/count.swig new file mode 100644 index 0000000000..19bb883db8 --- /dev/null +++ b/layout/_third-party/comments/changyan/count.swig @@ -0,0 +1,19 @@ +{% if theme.changyan.appid and theme.changyan.appkey %} + + + + {% if is_post() %} + + + + + {% else %} + + + + + {% endif %} + +{% endif %} diff --git a/layout/_third-party/comments/changyan.swig b/layout/_third-party/comments/changyan/index.swig similarity index 95% rename from layout/_third-party/comments/changyan.swig rename to layout/_third-party/comments/changyan/index.swig index cf8fd2c251..e58c7e5f74 100644 --- a/layout/_third-party/comments/changyan.swig +++ b/layout/_third-party/comments/changyan/index.swig @@ -1,3 +1,4 @@ +{% if theme.changyan.appid and theme.changyan.appkey %} {% if is_home() %} {% elif page.comments %} @@ -16,3 +17,4 @@ {% endif %} +{% endif %} diff --git a/layout/_third-party/comments/disqus/comment.swig b/layout/_third-party/comments/disqus/comment.swig new file mode 100644 index 0000000000..05b21b1a81 --- /dev/null +++ b/layout/_third-party/comments/disqus/comment.swig @@ -0,0 +1,9 @@ +{% if theme.disqus.shortname %} +
+
+ +
+
+{% endif %} diff --git a/layout/_third-party/comments/disqus/count.swig b/layout/_third-party/comments/disqus/count.swig new file mode 100644 index 0000000000..7be1bfe561 --- /dev/null +++ b/layout/_third-party/comments/disqus/count.swig @@ -0,0 +1,12 @@ +{% if theme.disqus.shortname %} + + + + + + + + +{% endif %} diff --git a/layout/_third-party/comments/disqus.swig b/layout/_third-party/comments/disqus/index.swig similarity index 94% rename from layout/_third-party/comments/disqus.swig rename to layout/_third-party/comments/disqus/index.swig index a2f0144279..1300c9d032 100644 --- a/layout/_third-party/comments/disqus.swig +++ b/layout/_third-party/comments/disqus/index.swig @@ -1,4 +1,5 @@ -{% if theme.disqus.count %} +{% if theme.disqus.shortname %} +{% if theme.comments.count.post or theme.comments.count.page %} {% endif %} +{% endif %} diff --git a/layout/_third-party/comments/disqusjs/comment.swig b/layout/_third-party/comments/disqusjs/comment.swig new file mode 100644 index 0000000000..0ff0658dcf --- /dev/null +++ b/layout/_third-party/comments/disqusjs/comment.swig @@ -0,0 +1,9 @@ +{% if theme.disqusjs.apikey and theme.disqusjs.shortname %} +
+
+ +
+
+{% endif %} diff --git a/layout/_third-party/comments/disqusjs.swig b/layout/_third-party/comments/disqusjs/index.swig similarity index 92% rename from layout/_third-party/comments/disqusjs.swig rename to layout/_third-party/comments/disqusjs/index.swig index c7b2f1fb72..ea0c6711e0 100644 --- a/layout/_third-party/comments/disqusjs.swig +++ b/layout/_third-party/comments/disqusjs/index.swig @@ -1,3 +1,4 @@ +{% if page.comments and theme.disqusjs.apikey and theme.disqusjs.shortname %} {% set disqusjs_css_url = '//cdn.jsdelivr.net/npm/disqusjs@1/dist/disqusjs.css' %} {% if theme.vendors.disqusjs_css %} {% set disqusjs_css_url = theme.vendors.disqusjs_css %} @@ -30,3 +31,4 @@ window.addEventListener('load', loadDsqJS, false); +{% endif %} diff --git a/layout/_third-party/comments/facebook_comments_plugin/comment.swig b/layout/_third-party/comments/facebook_comments_plugin/comment.swig new file mode 100644 index 0000000000..75a7c3a7f2 --- /dev/null +++ b/layout/_third-party/comments/facebook_comments_plugin/comment.swig @@ -0,0 +1,10 @@ +{% if theme.facebook_sdk.enable %} +
+
+
+
+{% endif %} diff --git a/layout/_third-party/comments/facebook_comments_plugin/count.swig b/layout/_third-party/comments/facebook_comments_plugin/count.swig new file mode 100644 index 0000000000..7eb5d9a4b9 --- /dev/null +++ b/layout/_third-party/comments/facebook_comments_plugin/count.swig @@ -0,0 +1,12 @@ +{% if theme.facebook_sdk.enable %} + + + + + + 0 + + +{% endif %} diff --git a/layout/_third-party/comments/gitalk/comment.swig b/layout/_third-party/comments/gitalk/comment.swig new file mode 100644 index 0000000000..ec5e8d0874 --- /dev/null +++ b/layout/_third-party/comments/gitalk/comment.swig @@ -0,0 +1 @@ +
diff --git a/layout/_third-party/comments/gitalk.swig b/layout/_third-party/comments/gitalk/index.swig similarity index 97% rename from layout/_third-party/comments/gitalk.swig rename to layout/_third-party/comments/gitalk/index.swig index 749ec59e9c..aa03b88dd8 100644 --- a/layout/_third-party/comments/gitalk.swig +++ b/layout/_third-party/comments/gitalk/index.swig @@ -1,3 +1,4 @@ +{% if page.comments %} {% set gitalk_js_url = '//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js' %} {% if theme.vendors.gitalk_js %} {% set gitalk_js_url = theme.vendors.gitalk_js %} @@ -33,3 +34,4 @@ }); gitalk.render('gitalk-container'); +{% endif %} diff --git a/layout/_third-party/comments/gitment/comment.swig b/layout/_third-party/comments/gitment/comment.swig new file mode 100644 index 0000000000..182c1adbd3 --- /dev/null +++ b/layout/_third-party/comments/gitment/comment.swig @@ -0,0 +1,8 @@ +
+ {% if theme.gitment.lazy %} +
{{ __('gitmentbutton') }}
+ + {% else %} +
+ {% endif %} +
diff --git a/layout/_third-party/comments/gitment/count.swig b/layout/_third-party/comments/gitment/count.swig new file mode 100644 index 0000000000..f2bf230776 --- /dev/null +++ b/layout/_third-party/comments/gitment/count.swig @@ -0,0 +1,12 @@ +{% if is_post() and theme.gitment.mint %} + + + + + + + + +{% endif %} diff --git a/layout/_third-party/comments/gitment.swig b/layout/_third-party/comments/gitment/index.swig similarity index 96% rename from layout/_third-party/comments/gitment.swig rename to layout/_third-party/comments/gitment/index.swig index d4f5ae06aa..fe833251fe 100644 --- a/layout/_third-party/comments/gitment.swig +++ b/layout/_third-party/comments/gitment/index.swig @@ -1,3 +1,4 @@ +{% if page.comments and theme.gitment.client_id %} {% if theme.gitment.mint %} {% set CommentsClass = 'Gitmint' %} @@ -43,3 +44,4 @@ } {% endif %} +{% endif %} diff --git a/layout/_third-party/comments/index.swig b/layout/_third-party/comments/index.swig index 51fd0e0855..6e19cd3d03 100644 --- a/layout/_third-party/comments/index.swig +++ b/layout/_third-party/comments/index.swig @@ -1,19 +1,4 @@ -{% if theme.disqus.enable %} - {% include 'disqus.swig' %} -{% elif theme.changyan.enable and theme.changyan.appid and theme.changyan.appkey %} - {% include 'changyan.swig' %} -{% elif theme.valine.enable and theme.valine.appid and theme.valine.appkey %} - {% include 'valine.swig' %} -{% endif %} - -{% if page.comments %} - {% if theme.livere_uid %} - {% include 'livere.swig' %} - {% elif theme.gitment.enable and theme.gitment.client_id %} - {% include 'gitment.swig' %} - {% elif theme.gitalk.enable %} - {% include 'gitalk.swig' %} - {% elif theme.disqusjs.enable and theme.disqusjs.apikey and theme.disqusjs.shortname %} - {% include 'disqusjs.swig' %} - {% endif %} +{% if theme.comments.type %} + {% set comments_index_path = '_third-party/comments/' + theme.comments.type|lower + '/index.swig' %} + {{ partial(comments_index_path) }} {% endif %} diff --git a/layout/_third-party/comments/livere/comment.swig b/layout/_third-party/comments/livere/comment.swig new file mode 100644 index 0000000000..c63a67cbac --- /dev/null +++ b/layout/_third-party/comments/livere/comment.swig @@ -0,0 +1,5 @@ +{% if theme.livere_uid %} +
+
+
+{% endif %} diff --git a/layout/_third-party/comments/livere.swig b/layout/_third-party/comments/livere/index.swig similarity index 86% rename from layout/_third-party/comments/livere.swig rename to layout/_third-party/comments/livere/index.swig index b14f5ed854..5afe6f6a65 100644 --- a/layout/_third-party/comments/livere.swig +++ b/layout/_third-party/comments/livere/index.swig @@ -1,3 +1,4 @@ +{% if page.comments and theme.livere_uid %} +{% endif %} diff --git a/layout/_third-party/comments/valine/comment.swig b/layout/_third-party/comments/valine/comment.swig new file mode 100644 index 0000000000..d273fe8b2e --- /dev/null +++ b/layout/_third-party/comments/valine/comment.swig @@ -0,0 +1,3 @@ +{% if theme.valine.appid and theme.valine.appkey %} +
+{% endif %} diff --git a/layout/_third-party/comments/valine/count.swig b/layout/_third-party/comments/valine/count.swig new file mode 100644 index 0000000000..44d200a4a5 --- /dev/null +++ b/layout/_third-party/comments/valine/count.swig @@ -0,0 +1,12 @@ +{% if theme.valine.appid and theme.valine.appkey %} + + + + + + + + +{% endif %} diff --git a/layout/_third-party/comments/valine.swig b/layout/_third-party/comments/valine/index.swig similarity index 94% rename from layout/_third-party/comments/valine.swig rename to layout/_third-party/comments/valine/index.swig index 7bfd1051b3..fe2cbfb47a 100644 --- a/layout/_third-party/comments/valine.swig +++ b/layout/_third-party/comments/valine/index.swig @@ -1,3 +1,4 @@ +{% if theme.valine.appid and theme.valine.appkey %} {% set leancloud_uri = '//cdn1.lncld.net/static/js/3.11.1/av-min.js' %} {% if theme.vendors.leancloud %} {% set leancloud_uri = theme.vendors.leancloud %} @@ -30,3 +31,4 @@ lang: '{{ theme.valine.language }}' || 'zh-cn' }); +{% endif %} diff --git a/layout/_third-party/comments/vkontakte/comment.swig b/layout/_third-party/comments/vkontakte/comment.swig new file mode 100644 index 0000000000..76bbd8f22d --- /dev/null +++ b/layout/_third-party/comments/vkontakte/comment.swig @@ -0,0 +1,5 @@ +{% if theme.vkontakte_api.enable %} +
+
+
+{% endif %} diff --git a/scripts/filters/views.js b/scripts/filters/views.js new file mode 100644 index 0000000000..2cba9667a0 --- /dev/null +++ b/scripts/filters/views.js @@ -0,0 +1,20 @@ +/* global hexo */ + +'use strict'; + +function setEmptyCommentsViews(fileName) { + let config = hexo.theme.config.comments; + if (!config.type) { + return; + } + let viewPath = `_third-party/comments/${config.type}/${fileName}`; + let view = hexo.theme.getView(`_third-party/comments/${config.type}/${fileName}`); + if (!view) { + hexo.theme.setView(viewPath, ''); + } +} + +hexo.extend.filter.register('before_generate', function() { + setEmptyCommentsViews('count.swig'); + setEmptyCommentsViews('index.swig'); +}); diff --git a/source/css/_common/components/third-party/third-party.styl b/source/css/_common/components/third-party/third-party.styl index 9797c1970e..16176b9d75 100644 --- a/source/css/_common/components/third-party/third-party.styl +++ b/source/css/_common/components/third-party/third-party.styl @@ -1,5 +1,5 @@ -@import "gitment" if hexo-config('gitment.enable'); -@import "gitalk" if hexo-config('gitalk.enable'); +@import "gitment" if hexo-config('comments.type') == 'gitment'; +@import "gitalk" if hexo-config('comments.type') == 'gitalk'; @import "localsearch"; @import "algolia-search" if hexo-config('algolia_search.enable'); @import "needsharebutton" if hexo-config('needmoreshare2.enable');