-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor comments using theme_inject (#998)
* Refactor comments * Use partial insteal of macro * Fix QA * Fix QA * Refactor priority * Format inject point
- Loading branch information
Showing
20 changed files
with
306 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,9 @@ | ||
{% 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.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.injects.comment.length == 1 %} | ||
{% set inject_item = theme.injects.comment[0] %} | ||
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }} | ||
{% endif %} | ||
|
||
{# {% for inject_item in theme.injects.comment %} | ||
{{ partial(inject_item.layout, inject_item.locals, inject_item.options) }} | ||
{% endfor %} #} | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* global hexo */ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
const {iconText} = require('./common'); | ||
const priority = hexo.config.inject_priority || {}; | ||
|
||
// Add comment | ||
hexo.extend.filter.register('theme_inject', function(injects) { | ||
let theme = hexo.theme.config; | ||
if (!theme.changyan.enable || !theme.changyan.appid || !theme.changyan.appkey) return; | ||
|
||
injects.comment.raw('changyan', ` | ||
<div class="comments" id="comments"> | ||
<div id="SOHUCS"></div> | ||
</div> | ||
`, {}, {cache: true}); | ||
|
||
injects.bodyEnd.file('changyan', path.join(hexo.theme_dir, 'layout/_third-party/comments/changyan.swig')); | ||
|
||
}, priority.changyan); | ||
|
||
// Add post_meta | ||
hexo.extend.filter.register('theme_inject', function(injects) { | ||
let theme = hexo.theme.config; | ||
if (!theme.changyan.enable || !theme.changyan.appid || !theme.changyan.appkey) return; | ||
|
||
injects.postMeta.raw('changyan', ` | ||
{% if post.comments %} | ||
<span class="post-meta-item"> | ||
${iconText} | ||
{% if is_post() %} | ||
<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 %} | ||
<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 %} | ||
`); | ||
|
||
}, priority.changyan_post_meta); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
iconText: ` | ||
<span class="post-meta-item-icon"> | ||
<i class="fa fa-comment-o"></i> | ||
</span> | ||
{% if theme.post_meta.item_text %} | ||
<span class="post-meta-item-text">{{ __('post.comments_count') + __('symbol.colon') }}</span> | ||
{% endif %} | ||
` | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* global hexo */ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
const {iconText} = require('./common'); | ||
const priority = hexo.config.inject_priority || {}; | ||
|
||
// Add comment | ||
hexo.extend.filter.register('theme_inject', function(injects) { | ||
let theme = hexo.theme.config; | ||
if (!theme.disqus.enable || !theme.disqus.shortname) return; | ||
|
||
injects.comment.raw('disqus', ` | ||
<div class="comments" id="comments"> | ||
<div id="disqus_thread"> | ||
<noscript>{# | ||
#}Please enable JavaScript to view the comments powered by Disqus.{# | ||
#}</noscript> | ||
</div> | ||
</div> | ||
`, {}, {cache: true}); | ||
|
||
injects.bodyEnd.file('disqus', path.join(hexo.theme_dir, 'layout/_third-party/comments/disqus.swig')); | ||
|
||
}, priority.disqus); | ||
|
||
// Add post_meta | ||
hexo.extend.filter.register('theme_inject', function(injects) { | ||
let theme = hexo.theme.config; | ||
if (!theme.disqus.enable || !theme.disqus.shortname || !theme.disqus.count) return; | ||
|
||
injects.postMeta.raw('disqus', ` | ||
{% if post.comments %} | ||
<span class="post-meta-item"> | ||
${iconText} | ||
<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 %} | ||
`); | ||
|
||
}, priority.disqus_post_meta); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* global hexo */ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
const priority = hexo.config.inject_priority || {}; | ||
|
||
// Add comment | ||
hexo.extend.filter.register('theme_inject', function(injects) { | ||
let theme = hexo.theme.config; | ||
if (!theme.disqusjs.enable || !theme.disqusjs.shortname || !theme.disqusjs.apikey) return; | ||
|
||
injects.comment.raw('disqusjs', ` | ||
<div class="comments" id="comments"> | ||
<div id="disqus_thread"> | ||
<noscript>{# | ||
#}Please enable JavaScript to view the comments powered by Disqus.{# | ||
#}</noscript> | ||
</div> | ||
</div> | ||
`, {}, {cache: true}); | ||
|
||
injects.bodyEnd.file('disqusjs', path.join(hexo.theme_dir, 'layout/_third-party/comments/disqusjs.swig')); | ||
|
||
}, priority.disqusjs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* global hexo */ | ||
|
||
'use strict'; | ||
|
||
const {iconText} = require('./common'); | ||
const priority = hexo.config.inject_priority || {}; | ||
|
||
// Add comment | ||
hexo.extend.filter.register('theme_inject', function(injects) { | ||
let theme = hexo.theme.config; | ||
if (!theme.facebook_sdk.enable || !theme.facebook_comments_plugin.enable) return; | ||
|
||
injects.comment.raw('facebook-comments-plugin', ` | ||
<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> | ||
`); | ||
|
||
}, priority.facebook_comments_plugin); | ||
|
||
// Add post_meta | ||
hexo.extend.filter.register('theme_inject', function(injects) { | ||
let theme = hexo.theme.config; | ||
if (!theme.facebook_sdk.enable || !theme.facebook_comments_plugin.enable) return; | ||
|
||
injects.postMeta.raw('facebook-comments-plugin', ` | ||
{% if post.comments %} | ||
<span class="post-meta-item"> | ||
${iconText} | ||
<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 %} | ||
`); | ||
|
||
}, priority.facebook_comments_plugin_post_meta); |
Oops, something went wrong.