Skip to content

Commit c56e61e

Browse files
committed
feat(comments): add support for CommentBox
1 parent 20cb4ae commit c56e61e

File tree

6 files changed

+86
-3
lines changed

6 files changed

+86
-3
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
Title: Comments -- Enable CommentBox
3+
Tags: interaction
4+
Category: Connecting With Your Readers
5+
Date: 2020-02-05 22:35
6+
Slug: enable-commentbox-comments
7+
Summary: Elegant offers CommentBox comments out of the box with few unique features
8+
authors: Talha Mansoor
9+
comment_id: 3a307b7d45
10+
commentbox_filter: off
11+
---
12+
13+
You can use [CommentBox](https://commentbox.io/) for comments. You have to set `COMMENTBOX_PROJECT` to your CommentBox project ID.
14+
15+
That's it. Elegant will take care of the rest.
16+
17+
You can see a working example of CommentBox comments in this article.
18+
19+
## Show CommentBox comments by default
20+
21+
Just set `COMMENTBOX_PROJECT` variable.
22+
23+
## Hide CommentBox comments by default
24+
25+
Unset `COMMENTBOX_PROJECT` variable.
26+
27+
This is the default setting.
28+
29+
## Hide CommentBox comments by default. Show on Selected
30+
31+
1. Set `COMMENTBOX_PROJECT`
32+
1. Set `COMMENTBOX_FILTER` to `True`
33+
34+
This will hide CommentBox form on all pages.
35+
36+
Now to show CommentBox form on selected posts, in article metadata set
37+
38+
```yaml
39+
commentbox_filter: off
40+
```
41+
42+
## Show CommentBox comments by default. Hide on Selected
43+
44+
1. Set `COMMENTBOX_PROJECT`
45+
1. Remove `COMMENTBOX_FILTER` or set it to `False` which is its default value
46+
47+
This will hide CommentBox form on all pages.
48+
49+
Now to hide CommentBox form on selected posts, in article metadata set
50+
51+
```yaml
52+
commentbox_filter: on
53+
```

documentation/pelicanconf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,4 @@
190190
}
191191
DISQUS_FILTER = True
192192
UTTERANCES_FILTER = True
193+
COMMENTBOX_FILTER = True

documentation/publishconf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
STAT_COUNTER_SECURITY = os.environ.get("STAT_COUNTER_SECURITY_PROD")
2323
GOOGLE_ANALYTICS = os.environ.get("GOOGLE_ANALYTICS_PROD")
2424
DISQUS_SITENAME = os.environ.get("DISQUS_SITENAME")
25+
COMMENTBOX_PROJECT = os.environ.get("COMMENTBOX_PROJECT")
2526

2627
elif os.environ.get("CONTEXT") == "branch-deploy" and os.environ.get("HEAD") == "next":
2728
SITENAME = "Elegant (Next)"

templates/_includes/_defaults.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
{% set UTTERANCES_LABEL = UTTERANCES_LABEL %}
8686
{% endif %}
8787

88+
{% if not COMMENTBOX_FILTER %}
89+
{% set COMMENTBOX_FILTER = False %}
90+
{% else %}
91+
{% set COMMENTBOX_FILTER = COMMENTBOX_FILTER %}
92+
{% endif %}
93+
8894
{# Author's twitter handle. Used in Twitter card meta data #}
8995
{% if not TWITTER_USERNAME %}
9096
{% set TWITTER_USERNAME = '' %}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% macro comments_script_commentbox(project, identifier) %}
2+
<div class="commentbox" id="{{ identifier }}"></div>
3+
<script src="https://unpkg.com/commentbox.io/dist/commentBox.min.js"></script>
4+
<script>
5+
commentBox("{{ project }}", {
6+
onCommentCount(count) {
7+
const ele = document.querySelector("#comment-accordion-toggle")
8+
if (ele && count > 0) {
9+
ele.innerText = `${count} Comment${count > 1 ? 's' : ''}`
10+
}
11+
}
12+
});
13+
</script>
14+
{% endmacro %}

templates/_includes/comments.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{% macro comments_section(article) %}
22

3-
{% from '_includes/_defaults.html' import DISQUS_FILTER, UTTERANCES_FILTER with context %}
3+
{% from '_includes/_defaults.html' import DISQUS_FILTER, UTTERANCES_FILTER, COMMENTBOX_FILTER with context %}
44

55
{% set use_disqus = (not DISQUS_FILTER or article.disqus_filter == "off") and DISQUS_SITENAME and article.disqus_filter != "on" %}
66

77
{% set use_utterances = (not UTTERANCES_FILTER or article.utterances_filter == "off") and UTTERANCES_REPO and article.utterances_filter != "on" %}
88

9+
{% set use_commentbox = (not COMMENTBOX_FILTER or article.commentbox_filter == "off") and COMMENTBOX_PROJECT and article.commentbox_filter != "on" %}
10+
911
{% set url = SITEURL+ '/' + article.url %}
1012
{% set identifier = SITEURL+ '/' + article.url %}
1113
{% if article.comment_id %}
@@ -20,7 +22,7 @@
2022
{% set intro = article.comments_intro %}
2123
{% endif %}
2224

23-
{% if article.status != 'draft' and article.comments != 'False' and (use_disqus or use_utterances) %}
25+
{% if article.status != 'draft' and article.comments != 'False' and (use_disqus or use_utterances or use_commentbox) %}
2426

2527
<section>
2628
<h6 style="display:none;">Comments</h6>
@@ -29,7 +31,7 @@ <h6 style="display:none;">Comments</h6>
2931
<div class="accordion" id="accordion2">
3032
<div class="accordion-group">
3133
<div class="accordion-heading">
32-
<a class="accordion-toggle disqus-comment-count comment-count"
34+
<a class="accordion-toggle disqus-comment-count comment-count collapsed"
3335
data-toggle="collapse"
3436
data-parent="#accordion2"
3537
{% if use_disqus %}
@@ -53,6 +55,12 @@ <h6 style="display:none;">Comments</h6>
5355
{% from '_includes/utterances_scripts.html' import comments_script_utterances with context %}
5456
{{ comments_script_utterances(UTTERANCES_REPO, identifier, UTTERANCES_LABEL, UTTERANCES_THEME) }}
5557
{% endif %}
58+
59+
60+
{% if use_commentbox %}
61+
{% from '_includes/commentbox_scripts.html' import comments_script_commentbox with context %}
62+
{{ comments_script_commentbox(COMMENTBOX_PROJECT, identifier) }}
63+
{% endif %}
5664
</div>
5765
</div>
5866
</div>

0 commit comments

Comments
 (0)