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 multi-comments #1048

Merged
merged 40 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2cba3b1
Add multi-comments
jiangtj Aug 3, 2019
1995b12
Update button style
jiangtj Aug 3, 2019
4a6ac1e
moblie
jiangtj Aug 3, 2019
741a0f5
Fix facebook comments button style
jiangtj Aug 3, 2019
ef99097
Fix QA
jiangtj Aug 3, 2019
9c9ad51
Fix comment length is 0
jiangtj Aug 3, 2019
058abd6
Rm log
jiangtj Aug 3, 2019
bfbaea6
Add vk style
jiangtj Aug 3, 2019
67b418c
check null
jiangtj Aug 3, 2019
3817362
Add localStorage
jiangtj Aug 3, 2019
2110957
Refactor localStorage
jiangtj Aug 3, 2019
9fb3335
...
jiangtj Aug 3, 2019
7f3b570
Update facebook style
jiangtj Aug 4, 2019
49349d1
Add custom button support
jiangtj Aug 4, 2019
6598b87
Fix null
jiangtj Aug 4, 2019
c8793b6
Merge branch 'master' into multi-comments
jiangtj Aug 4, 2019
96fc0f4
Add pjax
jiangtj Aug 4, 2019
368e02b
Fix pjax
jiangtj Aug 4, 2019
31b2329
Add tabs style
jiangtj Aug 5, 2019
e31ac2b
Update post meta
jiangtj Aug 5, 2019
7332e45
Fix defaultValue
jiangtj Aug 5, 2019
2fdefaa
Add title
jiangtj Aug 5, 2019
4bb84ce
Fix QA
jiangtj Aug 5, 2019
f344a09
Merge branch 'master' into multi-comments
jiangtj Aug 5, 2019
12695f4
Del i18n comments_count
jiangtj Aug 5, 2019
ae0613f
update
1v9 Aug 7, 2019
c241440
stylint
stevenjoezhang Aug 7, 2019
ab43c3b
Add configKey
jiangtj Aug 7, 2019
a36781e
Code style update
stevenjoezhang Aug 7, 2019
5591609
fix
jiangtj Aug 7, 2019
d923b02
m
jiangtj Aug 7, 2019
7b65cb0
Code style update
stevenjoezhang Aug 7, 2019
8cfbf71
Code style update
stevenjoezhang Aug 7, 2019
97a496e
add default comments.style
jiangtj Aug 7, 2019
40d0c98
Update
stevenjoezhang Aug 7, 2019
cd6b9b7
Merge branch 'multi-comments' of https://github.com/theme-next/hexo-t…
stevenjoezhang Aug 7, 2019
e5a3631
Fix
stevenjoezhang Aug 7, 2019
7a9bfa2
event
jiangtj Aug 7, 2019
2211ba4
Update
stevenjoezhang Aug 7, 2019
6125a6c
Update docs
stevenjoezhang Aug 7, 2019
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
16 changes: 15 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,21 @@ reading_progress:
# See: https://theme-next.org/docs/third-party-services/comments-and-widgets
# ---------------------------------------------------------------

# Multiple Comment System Support
comments:
# Available values: tabs | buttons
style: tabs
# Choose a comment system to be displayed by default
# Available values: changyan | disqus | disqusjs | facebook_comments_plugin | gitalk | livere | valine | vkontakte
active:
# Setting `true` means remembering the comment system selected by the visitor
storage: true
# Modify icons and texts for any style, here are some examples
nav:
#disqus: disqus
#facebook_comments_plugin: <i class="fa fa-facebook-official" aria-hidden="true"></i> facebook
#gitalk: Load Gitalk

# Disqus
disqus:
enable: false
Expand Down Expand Up @@ -907,7 +922,6 @@ note:

# Tabs tag
tabs:
enable: true
transition:
tabs: false
labels: true
Expand Down
1 change: 0 additions & 1 deletion languages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ post:
sticky: Sticky
toc_empty: This post does not have a Table of Contents
views: Views
comments_count: Comments
related_posts: Related Posts
copy_button: Copy
copy_success: Copied
Expand Down
78 changes: 75 additions & 3 deletions layout/_partials/comments.swig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,80 @@
{%- if theme.injects.comment.length == 1 %}
{%- set inject_item = theme.injects.comment[0] %}
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
{%- elif theme.injects.comment.length > 1 %}
{%- if theme.comments.style == 'buttons' %}
<div class="comment-button-group">
{%- for inject_item in theme.injects.comment %}
<a class="btn comment-button {{ inject_item.locals.class }}">{{ inject_item.locals.button }}</a>
{%- endfor %}
</div>
{%- for inject_item in theme.injects.comment %}
<div class="comment-position {{ inject_item.locals.class }}">
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
</div>
{%- endfor %}
<script{{ pjax }}>
(function() {
let commentButton = document.querySelectorAll('.comment-button');
commentButton.forEach(item => {
let commentClass = item.classList[2];
item.addEventListener('click', () => {
commentButton.forEach(rmActive => rmActive.classList.remove('active'));
item.classList.add('active');
document.querySelectorAll('.comment-position').forEach(rmActive => rmActive.classList.remove('active'));
document.querySelector(`.comment-position.${commentClass}`).classList.add('active');
{%- if theme.comments.storage %}
localStorage.setItem('comments_active', commentClass);
{%- endif %}
});
});
let activeClass = '{{ theme.comments.activeClass }}';
{%- if theme.comments.storage %}
activeClass = localStorage.getItem('comments_active') || activeClass;
{%- endif %}
if (activeClass) {
let activeButton = document.querySelector(`.comment-button.${activeClass}`);
if (activeButton) {
activeButton.click();
}
}
})();
</script>
{%- elif theme.comments.style == 'tabs' %}
<div class="tabs tabs-comment">
<ul class="nav-tabs">
{%- for inject_item in theme.injects.comment %}
<li class="tab"><a href="#comment-{{ inject_item.locals.class }}">{{ inject_item.locals.button }}</a></li>
{%- endfor %}
</ul>
<div class="tab-content">
{%- for inject_item in theme.injects.comment %}
<div class="tab-pane {{ inject_item.locals.class }}" id="comment-{{ inject_item.locals.class }}">
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
</div>
{%- endfor %}
</div>
</div>
<script>
window.addEventListener('tabs:register', function() {
let activeClass = '{{ theme.comments.activeClass }}';
{%- if theme.comments.storage %}
activeClass = localStorage.getItem('comments_active') || activeClass;
{%- endif %}
if (activeClass) {
let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
if (activeTab) {
activeTab.click();
}
}
});
{%- if theme.comments.storage %}
window.addEventListener('tabs:click', function(e) {
let commentClass = e.target.classList[1];
localStorage.setItem('comments_active', commentClass);
});
{%- endif %}
</script>
{%- endif %}
{%- endif %}
{# {%- for inject_item in theme.injects.comment %}
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }}
{%- endfor %} #}
{%- endif %}
1 change: 0 additions & 1 deletion layout/_partials/head/head.swig
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
},
localsearch: {{ theme.local_search | json_encode }},
path: '{{ config.search.path }}',
tabs: {{ theme.tabs.enable }},
motion: {{ theme.motion | json_encode }},
translation: {
copy_button: '{{__("post.copy_button")}}',
Expand Down
6 changes: 3 additions & 3 deletions scripts/filters/comment/changyan.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ hexo.extend.filter.register('theme_inject', injects => {
injects.postMeta.raw('changyan', `
{% if post.comments %}
<span class="post-meta-item">
${iconText}
${iconText('comment-o', 'changyan')}
{% if is_post() %}
<a href="{{ url_for(post.path) }}#SOHUCS" itemprop="discussionUrl">
<a title="changyan" 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 %}
<a href="{{ url_for(post.path) }}#SOHUCS" itemprop="discussionUrl">
<a title="changyan" 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 %}
Expand Down
25 changes: 19 additions & 6 deletions scripts/filters/comment/common.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
'use strict';

function capitalize(input) {
return input.toString().charAt(0).toUpperCase() + input.toString().substr(1);
}

module.exports = {
iconText: `
<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>
`
iconText(icon, key, defaultValue) {
if (!defaultValue) {
defaultValue = capitalize(key);
}
return `
<span class="post-meta-item-icon">
<i class="fa fa-${icon}"></i>
</span>
{%- set post_meta_comment = __('post.comments.${key}') %}
{%- if post_meta_comment == 'post.comments.${key}' %}
{%- set post_meta_comment = '${defaultValue}' %}
{%- endif %}
<span class="post-meta-item-text">{{ post_meta_comment + __('symbol.colon') }}</span>
`;
}
};
31 changes: 31 additions & 0 deletions scripts/filters/comment/default-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* global hexo */

'use strict';

const path = require('path');

hexo.extend.filter.register('theme_inject', injects => {
injects.comment.raws.forEach(element => {
// Set default button content
let injectName = path.basename(element.name, path.extname(element.name));
element.args[0] = Object.assign({
configKey: injectName,
class: injectName,
button: injectName
}, element.args[0]);
// Get locals and config
let locals = element.args[0];
let config = hexo.theme.config.comments;
// Set activeClass
if (config.active === locals.configKey) {
config.activeClass = locals.class;
}
// Set custom button content
if (config.nav) {
let customButton = config.nav[locals.configKey];
if (customButton) {
locals.button = customButton;
}
}
});
}, 99999);
4 changes: 2 additions & 2 deletions scripts/filters/comment/disqus.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ hexo.extend.filter.register('theme_inject', injects => {
injects.postMeta.raw('disqus', `
{% if post.comments %}
<span class="post-meta-item">
${iconText}
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
${iconText('comment-o', 'disqus')}
<a title="disqus" 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>
Expand Down
9 changes: 6 additions & 3 deletions scripts/filters/comment/facebook-comments-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ hexo.extend.filter.register('theme_inject', injects => {
data-colorscheme="{{ theme.facebook_comments_plugin.scheme }}">
</div>
</div>
`);
`, {
configKey: 'facebook_comments_plugin',
button: '<i class="fa fa-facebook-official" aria-hidden="true"></i> facebook'
});

}, priority.facebook_comments_plugin);

Expand All @@ -31,8 +34,8 @@ hexo.extend.filter.register('theme_inject', injects => {
injects.postMeta.raw('facebook-comments-plugin', `
{% if post.comments %}
<span class="post-meta-item">
${iconText}
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
${iconText('comment-o', 'facebook')}
<a title="facebook comments" 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>
Expand Down
4 changes: 2 additions & 2 deletions scripts/filters/comment/valine.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ hexo.extend.filter.register('theme_inject', injects => {
injects.postMeta.raw('valine', `
{% if post.comments and (is_post() or theme.valine.comment_count) %}
<span class="post-meta-item">
${iconText}
<a href="{{ url_for(post.path) }}#comments" itemprop="discussionUrl">
${iconText('comment-o', 'valine')}
<a title="valine" 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>
Expand Down
5 changes: 4 additions & 1 deletion scripts/filters/comment/vkontakte.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ hexo.extend.filter.register('theme_inject', injects => {
let theme = hexo.theme.config;
if (!theme.vkontakte_api.enable || !theme.vkontakte_api.comments) return;

injects.comment.raw('vkontakte-comments', '<div class="comments" id="comments"><div id="vk_comments"></div></div>', {}, {cache: true});
injects.comment.raw('vkontakte-comments', '<div class="comments" id="comments"><div id="vk_comments"></div></div>', {
configKey: 'vkontakte',
button: '<i class="fa fa-vk" aria-hidden="true"></i> vkontakte'
}, {cache: true});

}, priority.vkontakte_comments_plugin);
19 changes: 0 additions & 19 deletions scripts/filters/comment/warn.js

This file was deleted.

38 changes: 38 additions & 0 deletions source/css/_common/components/comments.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,41 @@
margin: 60px 20px 0;
overflow: hidden;
}

.comment-button-group {
display: flex;
flex-wrap: wrap-reverse;
justify-content: center;
margin: 1em 0;

.comment-button {
margin: 0.1em 0.2em;

&.active {
background: $btn-default-hover-bg;
border-color: $btn-default-hover-border-color;
color: $btn-default-hover-color;
}
}
}

.comment-position {
display: none;

&.active {
display: block;
}
}

.tabs-comment {
background: white;
margin-top: 4em;
padding-top: 0;

.comments {
border: 0;
box-shadow: none;
margin-top: 0;
padding-top: 0;
}
}
5 changes: 4 additions & 1 deletion source/css/_common/components/tags/tabs.styl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.post-body .tabs {
display: block;
margin-bottom: 20px;
}

.post-body .tabs, .tabs-comment {
display: block;
padding-top: 10px;
position: relative;
// Read tabs border_radius from NexT config and set in "$tbr px" to use it as string variable in this CSS section.
Expand Down
3 changes: 1 addition & 2 deletions source/css/_common/components/tags/tags.styl
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
@import 'blockquote-center';
@import 'group-pictures';
@import 'label';
@import 'tabs';

@import 'note' if (hexo-config('note.style') != 'disabled');

@import 'tabs' if (hexo-config('tabs.enable'));

@import 'pdf' if (hexo-config('pdf.enable'));
6 changes: 5 additions & 1 deletion source/css/_schemes/Gemini/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ $use-seo = hexo-config('seo');
padding: $content-desktop-padding;
}

.tabs-comment {
margin-top: 1em;
}

// Top main padding from header to posts (default 40px).
.posts-expand {
padding-top: initial;
Expand Down Expand Up @@ -239,7 +243,7 @@ $use-seo = hexo-config('seo');

.comments {
margin-top: $content-mobile-padding;
padding: 10 $sidebar-offset;
padding: 10px $sidebar-offset;
}

.pagination {
Expand Down
2 changes: 1 addition & 1 deletion source/js/next-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ $(document).on('DOMContentLoaded pjax:success', function() {
CONFIG.pangu && window.pangu.spacingPage();

CONFIG.copycode.enable && NexT.utils.registerCopyCode();
CONFIG.tabs && NexT.utils.registerTabsTag();
NexT.utils.registerTabsTag();
NexT.utils.registerActiveMenuItem();
NexT.utils.embeddedVideoTransformer();

Expand Down
6 changes: 6 additions & 0 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,14 @@ NexT.utils = {
$(this).addClass('active').siblings().removeClass('active');
var tActive = $(this).find('a').attr('href');
$(tActive).addClass('active').siblings().removeClass('active');
// Trigger event
document.querySelector(tActive).dispatchEvent(new Event('tabs:click', {
bubbles: true
}));
}
});

window.dispatchEvent(new Event('tabs:register'));
},

registerCanIUseTag: function() {
Expand Down