Skip to content

Commit

Permalink
feat(comments): add support for utterances comment system
Browse files Browse the repository at this point in the history
Fix #288
  • Loading branch information
talha131 committed Aug 17, 2019
1 parent 8c69c41 commit a2151cc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions documentation/pelicanconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,4 @@
},
}
DISQUS_FILTER = True
UTTERANCES_FILTER = True
2 changes: 2 additions & 0 deletions documentation/publishconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
SITEURL = ""

MAILCHIMP_FORM_ACTION = os.environ.get("MAILCHIMP_FORM_ACTION")
UTTERANCES_REPO = "Pelican-Elegant/elegant"
UTTERANCES_LABEL = "💬documentation-comments"

RELATIVE_URLS = False
# filetime_from_git is very slow. Use it in production only
Expand Down
18 changes: 18 additions & 0 deletions templates/_includes/_defaults.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@
{% set DISQUS_FILTER = DISQUS_FILTER %}
{% endif %}

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

{% if not UTTERANCES_THEME %}
{% set UTTERANCES_THEME = 'github-light' %}
{% else %}
{% set UTTERANCES_THEME = UTTERANCES_THEME %}
{% endif %}

{% if not UTTERANCES_LABEL %}
{% set UTTERANCES_LABEL = '' %}
{% else %}
{% set UTTERANCES_LABEL = UTTERANCES_LABEL %}
{% endif %}

{# Author's twitter handle. Used in Twitter card meta data #}
{% if not TWITTER_USERNAME %}
{% set TWITTER_USERNAME = '' %}
Expand Down
12 changes: 10 additions & 2 deletions templates/_includes/comments.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{% macro comments_section(article) %}

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

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

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

{% set identifier = SITEURL+ '/' + article.url %}
{% if article.comment_id %}
{% set identifier = article.comment_id %}
Expand All @@ -16,7 +19,7 @@
{% set intro = article.comments_intro %}
{% endif %}

{% if article.status != 'draft' and article.comments != 'False' and (use_disqus) %}
{% if article.status != 'draft' and article.comments != 'False' and (use_disqus or use_utterances) %}

<section>
<h6 style="display:none;">Comments</h6>
Expand All @@ -42,6 +45,11 @@ <h6 style="display:none;">Comments</h6>
{% if use_disqus %}
<div id="disqus_thread"></div>
{% endif %}

{% if use_utterances %}
{% from '_includes/utterances_scripts.html' import comments_script_utterances with context %}
{{ comments_script_utterances(UTTERANCES_REPO, identifier, UTTERANCES_LABEL, UTTERANCES_THEME) }}
{% endif %}
</div>
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions templates/_includes/utterances_scripts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% macro comments_script_utterances(repo, id, label, theme) %}
<script src="https://utteranc.es/client.js"
repo="{{ repo }}"
issue-term="{{ id }}"
label="{{ label }}"
theme="{{ theme }}"
crossorigin="anonymous"
async>
</script>
{% endmacro %}

0 comments on commit a2151cc

Please sign in to comment.