Skip to content

Commit

Permalink
feat(filter): add black list, white list feature for Disqus
Browse files Browse the repository at this point in the history
  • Loading branch information
talha131 committed Jul 30, 2019
1 parent 7a41ab8 commit 4887aec
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
40 changes: 40 additions & 0 deletions documentation/content/Comments/disqus-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,49 @@ comment_id: 9jgwmy8-how-to-use-disqus-comments-elegantly
Subtitle:
Summary: Elegant offers Disqus comments out of the box with few unique features
authors: Talha Mansoor
comment_id: aa8pfjdv5f
disqus_filter: off
---

You can use Disqus for comments. You have to set `DISQUS_SITENAME` to Disqus
site name identifier in configuration to enable comments.

That's it. Elegant will take care of the rest.

You can see a working example of Disqus comments in this article.

## Show Disqus comments by default

Just set `DISQUS_SITENAME` variable.

## Hide Disqus comments by default

Unset `DISQUS_SITENAME` variable.

This is the default setting.

## Hide Disqus comments by default. Show on Selected

1. Set `DISQUS_SITENAME`
1. Set `DISQUS_FILTER` to `True`

This will hide Disqus form on all pages.

Now to show Disqus form on selected posts, in article metadata set

```yaml
disqus_filter: off
```
## Show Disqus comments by default. Hide on Selected
1. Set `DISQUS_SITENAME`
1. Remove `DISQUS_FILTER` or set it to `False` which is its default value

This will hide Disqus form on all pages.

Now to hide Disqus form on selected posts, in article metadata set

```yaml
disqus_filter: on
```
1 change: 1 addition & 0 deletions documentation/pelicanconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,4 @@
"blurb": "FOSS lawyer by trade, hacker by heart.",
},
}
DISQUS_FILTER = True
6 changes: 6 additions & 0 deletions templates/_includes/_defaults.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
{% set COMMENTS_INTRO = COMMENTS_INTRO %}
{% endif %}

{% if not DISQUS_FILTER %}
{% set DISQUS_FILTER = False %}
{% else %}
{% set DISQUS_FILTER = DISQUS_FILTER %}
{% endif %}

{# Author's twitter handle. Used in Twitter card meta data #}
{% if not TWITTER_USERNAME %}
{% set TWITTER_USERNAME = '' %}
Expand Down
15 changes: 13 additions & 2 deletions templates/_includes/comments.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{% macro comments(article) %}
{% if DISQUS_SITENAME and SITEURL and article.status != 'draft' and article.comments != 'False' %}
{% if SITEURL and article.status != 'draft' and article.comments != 'False' %}

{% from '_includes/_defaults.html' import DISQUS_FILTER with context %}

{%if (not DISQUS_FILTER or article.disqus_filter == "off") and DISQUS_SITENAME and article.disqus_filter != "on" %}

<section>
{% if article.comments_intro %}
<p id="comment-message">{{ article.comments_intro }} </p>
Expand Down Expand Up @@ -35,11 +40,17 @@
</div>
</section>
{% endif %}
{% endif %}
{% endmacro %}

{% macro comments_script(article) %}
{% if DISQUS_SITENAME and SITEURL and article.status != 'draft' %}
{% if SITEURL and article.status != 'draft' %}
{% from '_includes/_defaults.html' import DISQUS_FILTER with context %}

{%if (not DISQUS_FILTER or article.disqus_filter == "off") and DISQUS_SITENAME and article.disqus_filter != "on" %}

{% from '_includes/disqus_scripts.html' import disqus_misc_scripts with context %}
{{ disqus_misc_scripts() }}
{% endif %}
{% endif %}
{% endmacro %}

0 comments on commit 4887aec

Please sign in to comment.