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

Add comment_count option #559

Merged
merged 9 commits into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ cheers_enabled: true
# - All fonts set here will have the following styles:
# light, light italic, normal, normal italic, bold, bold italic
# - Be aware that setting too much fonts will cause site running slowly
# - Introduce in 5.0.1
# - Introduced in 5.0.1
# ---------------------------------------------------------------
# CAUTION! Safari Version 10.1.2 bug: https://github.com/iissnan/hexo-theme-next/issues/1844
# To avoid space between header and sidebar in Pisces / Gemini themes recommended to use Web Safe fonts for `global` (and `logo`):
Expand Down Expand Up @@ -523,7 +523,7 @@ disqus:
count: true
lazyload: false

# changyan
# Changyan
changyan:
enable: false
appid:
Expand All @@ -543,6 +543,7 @@ valine:
guest_info: nick,mail,link # custom comment header
pageSize: 10 # pagination size
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

# Support for LiveRe comments system.
# You can get your uid from https://livere.com/insight/myCode (General web site)
Expand Down Expand Up @@ -583,7 +584,8 @@ gitalk:
#baidushare:
## type: button

# addthis Share, see: https://www.addthis.com
# AddThis Share, See: https://www.addthis.com
# Go to https://www.addthis.com/dashboard to customize your tools
#add_this_id:

# NeedMoreShare2
Expand Down
44 changes: 22 additions & 22 deletions layout/_macro/post.swig
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span> <span class="post-comments-count gitment-comments-count" data-xid="{{ url_for(post.path) }}" itemprop="commentsCount"></span>
</a>
</span>
{% elseif theme.valine.enable and theme.valine.appid and theme.valine.appkey %}
{% elseif (is_post() or theme.valine.comment_count) and theme.valine.enable and theme.valine.appid and theme.valine.appkey %}
<span class="post-comments-count">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
Expand All @@ -203,16 +203,16 @@

{# LeanCould PageView #}
{% if theme.leancloud_visitors.enable or (theme.valine.enable and theme.valine.appid and theme.valine.appkey and theme.valine.visitor) %}
<span id="{{ url_for(post.path) }}" class="leancloud_visitors" data-flag-title="{{ post.title }}">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-eye"></i>
</span>
{% if theme.post_meta.item_text %}
<span class="post-meta-item-text">{{__('post.views') + __('symbol.colon') }}</span>
{% endif %}
<span class="leancloud-visitors-count"></span>
</span>
<span id="{{ url_for(post.path) }}" class="leancloud_visitors" data-flag-title="{{ post.title }}">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-eye"></i>
</span>
{% if theme.post_meta.item_text %}
<span class="post-meta-item-text">{{ __('post.views') + __('symbol.colon') }}</span>
{% endif %}
<span class="leancloud-visitors-count"></span>
</span>
{% endif %}

{% if not is_index and theme.busuanzi_count.enable and theme.busuanzi_count.post_views %}
Expand Down Expand Up @@ -262,8 +262,8 @@
{% endif %}

{% if post.description and (not theme.excerpt_description or not is_index) %}
<div class="post-description">{#
#}{{ post.description }}{#
<div class="post-description">{#
#}{{ post.description }}{#
#}</div>
{% endif %}

Expand Down Expand Up @@ -396,7 +396,7 @@

{% if (theme.vkontakte_api.enable and theme.vkontakte_api.like) or (theme.facebook_sdk.enable and theme.facebook_sdk.like_button) %}
{% if theme.rating.enable %}
<span class="post-meta-divider">|</span>
<span class="post-meta-divider">|</span>
{% endif %}
<div class="social-like">
{% if theme.vkontakte_api.enable and theme.vkontakte_api.like %}
Expand All @@ -419,16 +419,16 @@
{% endif %}
<div class="social_share">
{% if theme.baidushare.type === "button" %}
<div>
{% include '../_partials/share/baidushare.swig' %}
</div>
<div>
{% include '../_partials/share/baidushare.swig' %}
</div>
{% endif %}
{% if theme.needmoreshare2.enable and theme.needmoreshare2.postbottom.enable %}
<div id="needsharebutton-postbottom">
<span class="btn">
<i class="fa fa-share-alt" aria-hidden="true"></i>
</span>
</div>
<div id="needsharebutton-postbottom">
<span class="btn">
<i class="fa fa-share-alt" aria-hidden="true"></i>
</span>
</div>
{% endif %}
</div>
{% endif %}
Expand Down
75 changes: 37 additions & 38 deletions layout/_third-party/analytics/lean-analytics.swig
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
{% if theme.leancloud_visitors.enable and !theme.valine.visitor %}

{# custom analytics part create by xiamo; edited by LEAFERx #}
<script>
{% if page.layout === 'post' %}
function addCount(Counter) {
var $visitors = $(".leancloud_visitors");
var $visitors = $('.leancloud_visitors');
var url = $visitors.attr('id').trim();
var title = $visitors.attr('data-flag-title').trim();

Counter('get', '/classes/Counter', { where: JSON.stringify({ url }) })
.done(function ({ results }) {
.done(function({ results }) {
if (results.length > 0) {
var counter = results[0];
{% if theme.leancloud_visitors.betterPerformance %}
var $element = $(document.getElementById(url));
$element.find('.leancloud-visitors-count').text(counter.time + 1);
{% endif %}
Counter('put', `/classes/Counter/${counter.objectId}`, JSON.stringify({ time: { "__op":"Increment", "amount":1 } }))
Counter('put', '/classes/Counter/' + counter.objectId, JSON.stringify({ time: { '__op': 'Increment', 'amount': 1 } }))
{% if not theme.leancloud_visitors.betterPerformance %}
.done(function () {
var $element = $(document.getElementById(url));
$element.find('.leancloud-visitors-count').text(counter.time + 1);
})
.done(function() {
var $element = $(document.getElementById(url));
$element.find('.leancloud-visitors-count').text(counter.time + 1);
})
{% endif %}
.fail(function ({ responseJSON }) {
.fail(function({ responseJSON }) {
console.log('Failed to save Visitor num, with error message: ' + responseJSON.error);
})
})
} else {
{% if theme.leancloud_visitors.security %}
var $element = $(document.getElementById(url));
$element.find('.leancloud-visitors-count').text('Counter not initialized! See more at console err msg.');
console.error('ATTENTION! LeanCloud counter has security bug, see here how to solve it: https://github.com/theme-next/hexo-leancloud-counter-security. \n But you also can use LeanCloud without security, by set \'security\' option to \'false\'.');
$element.find('.leancloud-visitors-count').text('Counter not initialized! More info at console err msg.');
console.error('ATTENTION! LeanCloud counter has security bug, see how to solve it here: https://github.com/theme-next/hexo-leancloud-counter-security. \n However, you can still use LeanCloud without security, by setting `security` option to `false`.');
{% else %}
Counter('post', '/classes/Counter', JSON.stringify({ title: title, url: url, time: 1}))
.done(function () {
Counter('post', '/classes/Counter', JSON.stringify({ title: title, url: url, time: 1 }))
.done(function() {
var $element = $(document.getElementById(url));
$element.find('.leancloud-visitors-count').text(1);
})
.fail(function () {
.fail(function() {
console.log('Failed to create');
});
{% endif %}
}
})
.fail(function ({ responseJSON }) {
console.log('LeanCloud Counter Error:' + responseJSON.code + " " + responseJSON.error);
.fail(function({ responseJSON }) {
console.log('LeanCloud Counter Error: ' + responseJSON.code + ' ' + responseJSON.error);
});
}
{% else %}
function showTime(Counter) {
var entries = [];
var $visitors = $(".leancloud_visitors");
var $visitors = $('.leancloud_visitors');

$visitors.each(function () {
entries.push( $(this).attr("id").trim() );
$visitors.each(function() {
entries.push( $(this).attr('id').trim() );
});

Counter('get', '/classes/Counter', { where: JSON.stringify({ url: { "$in": entries } }) })
.done(function ({ results }) {
Counter('get', '/classes/Counter', { where: JSON.stringify({ url: { '$in': entries } }) })
.done(function({ results }) {
var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

if (results.length === 0) {
Expand All @@ -73,44 +72,44 @@

$(element).find(COUNT_CONTAINER_REF).text(time);
}
for(var i = 0; i < entries.length; i++) {
for (var i = 0; i < entries.length; i++) {
var url = entries[i];
var element = document.getElementById(url);
var countSpan = $(element).find(COUNT_CONTAINER_REF);
if( countSpan.text() == '') {
if (countSpan.text() == '') {
countSpan.text(0);
}
}
})
.fail(function ({ responseJSON }) {
console.log("LeanCloud Counter Error: " + responseJSON.code + " " + responseJSON.error);
.fail(function({ responseJSON }) {
console.log('LeanCloud Counter Error: ' + responseJSON.code + ' ' + responseJSON.error);
});
}
{% endif %}

$(function() {
$.get('https://app-router.leancloud.cn/2/route?appId=' + "{{theme.leancloud_visitors.app_id}}")
.done(function ({ api_server }) {
var Counter = function (method, url, data) {
$.get('https://app-router.leancloud.cn/2/route?appId=' + '{{ theme.leancloud_visitors.app_id }}')
.done(function({ api_server }) {
var Counter = function(method, url, data) {
return $.ajax({
method: method,
url: `https://${api_server}/1.1${url}`,
url: 'https://' + api_server + '/1.1' + url,
headers: {
'X-LC-Id': "{{theme.leancloud_visitors.app_id}}",
'X-LC-Key': "{{theme.leancloud_visitors.app_key}}",
'X-LC-Id': '{{ theme.leancloud_visitors.app_id }}',
'X-LC-Key': '{{ theme.leancloud_visitors.app_key }}',
'Content-Type': 'application/json',
},
data: data,
data: data
});
};
{% if page.layout === 'post' %}
addCount(Counter);
addCount(Counter);
{% else %}
if ($('.post-title-link').length >= 1) {
showTime(Counter);
}
if ($('.post-title-link').length >= 1) {
showTime(Counter);
}
{% endif %}
})
});
});
</script>

Expand Down
8 changes: 4 additions & 4 deletions layout/_third-party/comments/valine.swig
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
<script src="{{ leancloud_uri }}"></script>
<script src="{{ valine_uri }}"></script>
<script>
var GUEST = ['nick','mail','link'];
var GUEST = ['nick', 'mail', 'link'];
var guest = '{{ theme.valine.guest_info }}';
guest = guest.split(',').filter(function (item) {
guest = guest.split(',').filter(function(item) {
return GUEST.indexOf(item) > -1;
});
new Valine({
el: '#comments' ,
el: '#comments',
verify: {{ theme.valine.verify }},
notify: {{ theme.valine.notify }},
appId: '{{ theme.valine.appid }}',
appKey: '{{ theme.valine.appkey }}',
placeholder: '{{ theme.valine.placeholder }}',
avatar: '{{ theme.valine.avatar }}',
meta:guest,
meta: guest,
pageSize: '{{ theme.valine.pageSize }}' || 10,
visitor: {{ theme.valine.visitor }}
});
Expand Down