Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring comments #711

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 12 additions & 11 deletions _config.yml
Expand Up @@ -598,20 +598,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
Expand All @@ -623,15 +631,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
Expand All @@ -642,7 +649,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)
Expand All @@ -651,9 +657,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
Expand All @@ -667,7 +671,6 @@ gitment:
# Gitalk
# Demo: https://gitalk.github.io
gitalk:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You delete options from comments above?

enable: false
github_id: # Github repo owner
repo: # Repository name to store issues
client_id: # Github Application Client ID
Expand Down Expand Up @@ -777,7 +780,6 @@ facebook_sdk:
# This plugin depends on Facebook SDK.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carefully here. Facebook, like VK, have own SDK (API). I think need to make similar as VK.

# 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)
Expand All @@ -788,7 +790,6 @@ vkontakte_api:
enable: false
app_id: #<app_id>
like: true
comments: true
num_of_posts: 10

# Star rating support to each article.
Expand Down
53 changes: 5 additions & 48 deletions layout/_macro/post.swig
Expand Up @@ -139,54 +139,11 @@
{% endif %}

{% if post.comments %}
{% macro comments() %}
<span class="post-comments-count">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
{% endmacro %}
{% if theme.facebook_comments_plugin.enable %}
{{ comments() }}
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
<span class="post-comments-count fb-comments-count" data-href="{{ post.permalink }}" itemprop="commentCount">0</span>
</a>
</span>
{% elif theme.disqus.enable and theme.disqus.count %}
{{ comments() }}
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="{{ post.path }}" itemprop="commentCount"></span>
</a>
</span>
{% elif theme.changyan.enable and theme.changyan.appid and theme.changyan.appkey %}
{{ comments() }}
{% if is_post() %}
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#SOHUCS" itemprop="discussionUrl">
<span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="{{ post.path }}" itemprop="commentCount"></span>
</a>
{% else %}
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#SOHUCS" itemprop="discussionUrl">
<span id="url::{{ post.permalink }}" class="cy_cmt_count" data-xid="{{ post.path }}" itemprop="commentCount"></span>
</a>
{% endif %}
{% elif is_post() and theme.gitment.enable and theme.gitment.mint and theme.gitment.count %}
{{ comments() }}
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
<span class="post-comments-count gitment-comments-count" data-xid="{{ url_for(post.path) }}" itemprop="commentCount"></span>
</a>
</span>
{% elif (is_post() or theme.valine.comment_count) and theme.valine.enable and theme.valine.appid and theme.valine.appkey %}
{{ comments() }}
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
<span class="post-comments-count valine-comment-count" data-xid="{{ url_for(post.path) }}" itemprop="commentCount"></span>
</a>
</span>
{% 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 %}

Expand Down
57 changes: 3 additions & 54 deletions layout/_partials/comments.swig
@@ -1,57 +1,6 @@
{% if page.comments %}

{% if theme.facebook_sdk.enable and theme.facebook_comments_plugin.enable %}
<div class="comments" id="comments">
<div class="fb-comments"
data-href="{{ page.permalink }}"
data-numposts="{{ theme.facebook_comments_plugin.num_of_posts }}"
data-width="{{ theme.facebook_comments_plugin.width }}"
data-colorscheme="{{ theme.facebook_comments_plugin.scheme }}">
</div>
</div>

{% elif theme.vkontakte_api.enable and theme.vkontakte_api.comments %}
<div class="comments" id="comments">
<div id="vk_comments"></div>
</div>

{% elif theme.disqus.enable or (theme.disqusjs.enable and theme.disqusjs.apikey and theme.disqusjs.shortname) %}
<div class="comments" id="comments">
<div id="disqus_thread">
<noscript>{#
#}Please enable JavaScript to view the comments powered by Disqus.{#
#}</noscript>
</div>
</div>

{% elif theme.livere_uid %}
<div class="comments" id="comments">
<div id="lv-container" data-id="city" data-uid="{{ theme.livere_uid }}"></div>
</div>

{% elif theme.changyan.enable and theme.changyan.appid and theme.changyan.appkey %}
<div class="comments" id="comments">
<div id="SOHUCS"></div>
</div>

{% elif theme.gitment.enable %}
<div class="comments" id="comments">
{% if theme.gitment.lazy %}
<div onclick="showGitment()" id="gitment-display-button">{{ __('gitmentbutton') }}</div>
<div id="gitment-container" style="display: none"></div>
{% else %}
<div id="gitment-container"></div>
{% endif %}
</div>

{% elif theme.valine.enable and theme.valine.appid and theme.valine.appkey %}
<div class="comments" id="comments">
</div>

{% elif theme.gitalk.enable %}
<div class="comments" id="gitalk-container">
</div>

{% if theme.comments.type %}
{% set comments_comment_path = '_third-party/comments/' + theme.comments.type|lower + '/comment.swig' %}
{{ partial(comments_comment_path) }}
{% endif %}

{% endif %}
2 changes: 1 addition & 1 deletion layout/_third-party/analytics/vkontakte-api.swig
Expand Up @@ -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 %}
};
Expand Down
5 changes: 5 additions & 0 deletions layout/_third-party/comments/changyan/comment.swig
@@ -0,0 +1,5 @@
{% if theme.changyan.appid and theme.changyan.appkey %}
<div class="comments" id="comments">
<div id="SOHUCS"></div>
</div>
{% endif %}
19 changes: 19 additions & 0 deletions layout/_third-party/comments/changyan/count.swig
@@ -0,0 +1,19 @@
{% if theme.changyan.appid and theme.changyan.appkey %}
<span class="post-comments-count">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
{% if is_post() %}
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#SOHUCS" itemprop="discussionUrl">
<span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="{{ post.path }}" itemprop="commentCount"></span>
</a>
{% else %}
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#SOHUCS" itemprop="discussionUrl">
<span id="url::{{ post.permalink }}" class="cy_cmt_count" data-xid="{{ post.path }}" itemprop="commentCount"></span>
</a>
{% endif %}
</span>
{% endif %}
@@ -1,3 +1,4 @@
{% if theme.changyan.appid and theme.changyan.appkey %}
{% if is_home() %}
<script id="cy_cmt_num" src="https://changyan.sohu.com/upload/plugins/plugins.list.count.js?clientId={{ theme.changyan.appid }}"></script>
{% elif page.comments %}
Expand All @@ -16,3 +17,4 @@
</script>
<script src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js"></script>
{% endif %}
{% endif %}
9 changes: 9 additions & 0 deletions layout/_third-party/comments/disqus/comment.swig
@@ -0,0 +1,9 @@
{% if theme.disqus.shortname %}
<div class="comments" id="comments">
<div id="disqus_thread">
<noscript>{#
#}Please enable JavaScript to view the comments powered by Disqus.{#
#}</noscript>
</div>
</div>
{% endif %}
12 changes: 12 additions & 0 deletions layout/_third-party/comments/disqus/count.swig
@@ -0,0 +1,12 @@
{% if theme.disqus.shortname %}
<span class="post-comments-count">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="{{ post.path }}" itemprop="commentCount"></span>
</a>
</span>
{% endif %}
@@ -1,4 +1,5 @@
{% if theme.disqus.count %}
{% if theme.disqus.shortname %}
{% if theme.comments.count.post or theme.comments.count.page %}
<script id="dsq-count-scr" src="https://{{ theme.disqus.shortname }}.disqus.com/count.js" async></script>
{% endif %}
{% if page.comments %}
Expand Down Expand Up @@ -42,3 +43,4 @@
{% endif %}
</script>
{% endif %}
{% endif %}
9 changes: 9 additions & 0 deletions layout/_third-party/comments/disqusjs/comment.swig
@@ -0,0 +1,9 @@
{% if theme.disqusjs.apikey and theme.disqusjs.shortname %}
<div class="comments" id="comments">
<div id="disqus_thread">
<noscript>{#
#}Please enable JavaScript to view the comments powered by Disqus.{#
#}</noscript>
</div>
</div>
{% endif %}
@@ -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 %}
Expand All @@ -17,3 +18,4 @@
shortname: '{{ theme.disqusjs.shortname }}'
});
</script>
{% endif %}
10 changes: 10 additions & 0 deletions layout/_third-party/comments/facebook_comments_plugin/comment.swig
@@ -0,0 +1,10 @@
{% if theme.facebook_sdk.enable %}
<div class="comments" id="comments">
<div class="fb-comments"
data-href="{{ page.permalink }}"
data-numposts="{{ theme.facebook_comments_plugin.num_of_posts }}"
data-width="{{ theme.facebook_comments_plugin.width }}"
data-colorscheme="{{ theme.facebook_comments_plugin.scheme }}">
</div>
</div>
{% endif %}
12 changes: 12 additions & 0 deletions layout/_third-party/comments/facebook_comments_plugin/count.swig
@@ -0,0 +1,12 @@
{% if theme.facebook_sdk.enable %}
<span class="post-comments-count">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
<span class="post-comments-count fb-comments-count" data-href="{{ post.permalink }}" itemprop="commentCount">0</span>
</a>
</span>
{% endif %}
1 change: 1 addition & 0 deletions layout/_third-party/comments/gitalk/comment.swig
@@ -0,0 +1 @@
<div class="comments" id="gitalk-container"></div>
@@ -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 %}
Expand Down Expand Up @@ -33,3 +34,4 @@
});
gitalk.render('gitalk-container');
</script>
{% endif %}
8 changes: 8 additions & 0 deletions layout/_third-party/comments/gitment/comment.swig
@@ -0,0 +1,8 @@
<div class="comments" id="comments">
{% if theme.gitment.lazy %}
<div onclick="showGitment()" id="gitment-display-button">{{ __('gitmentbutton') }}</div>
<div id="gitment-container" style="display: none"></div>
{% else %}
<div id="gitment-container"></div>
{% endif %}
</div>
12 changes: 12 additions & 0 deletions layout/_third-party/comments/gitment/count.swig
@@ -0,0 +1,12 @@
{% if is_post() and theme.gitment.mint %}
<span class="post-comments-count">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span>
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
<span class="post-comments-count gitment-comments-count" data-xid="{{ url_for(post.path) }}" itemprop="commentsCount"></span>
</a>
</span>
{% endif %}
@@ -1,3 +1,4 @@
{% if page.comments and theme.gitment.client_id %}
<!-- LOCAL: You can save these files to your site and update links -->
{% if theme.gitment.mint %}
{% set CommentsClass = 'Gitmint' %}
Expand Down Expand Up @@ -43,3 +44,4 @@
}
{% endif %}
</script>
{% endif %}