Skip to content

Commit

Permalink
feat: add uterrances support
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-W committed Jan 26, 2022
1 parent fbe73a2 commit 2367068
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
27 changes: 15 additions & 12 deletions static/js/script.js
Expand Up @@ -132,19 +132,22 @@ jQuery(function($) {
Initialize and load Disqus
========================================================================== */

if (typeof disqus === 'undefined') {
if (typeof disqus === 'undefined' && typeof use_utterance === 'undefined') {
$('.post-comments').css({
'display' : 'none'
});
} else {
$('#show-disqus').on('click', function() {
$.ajax({
type: "GET",
url: "//" + disqus + ".disqus.com/embed.js",
dataType: "script",
cache: true
});
$(this).parent().addClass('activated');
});
}
} else if (typeof use_utterance === 'undefined') {
$('#show-comments').on(
'click',
function() {
$.ajax({
type: "GET",
url: "//" + disqus + ".disqus.com/embed.js",
dataType: "script",
cache: true
});
$(this).parent().addClass('activated');
}
);
}
});
20 changes: 18 additions & 2 deletions templates/article.html
@@ -1,3 +1,4 @@

{% extends "base.html" %}

{% block title %}{{ article.title }}{% endblock %}
Expand Down Expand Up @@ -200,12 +201,27 @@ <h4 class="post-author-name"><a href="{{ SITEURL }}/{{author.url}}">{{author_nam
<noscript>Please enable JavaScript to view the comments.</noscript>
<section class="post-comments">
{% if article.disqus_identifier %}
<a id="show-disqus" class="post-comments-activate" data-disqus-identifier="{{ article.disqus_identifier }}" >Show Comments</a>
<a id="show-comments" class="post-comments-activate" data-disqus-identifier="{{ article.disqus_identifier }}" >Show Comments</a>
{% else %}
<a id="show-disqus" class="post-comments-activate" data-disqus-identifier="/{{ article.url }}" >Show Comments</a>
<a id="show-comments" class="post-comments-activate" data-disqus-identifier="/{{ article.url }}" >Show Comments</a>
{% endif %}
<div id="disqus_thread"></div>
</section>

{% elif UTTERANCES_REPO and SITEURL and article.status != "draft" %}
{% from 'partials/_defaults.html' import UTTERANCES_FILTER, UTTERANCES_THEME, UTTERANCES_LABEL with context %}
{% set identifier = SITEURL+ '/' + article.url %}
{% if article.comment_id %}
{% set identifier = article.comment_id %}
{% elif article.disqus_identifier %}
{% set identifier = article.disqus_identifier %}
{% endif %}

<script type="text/javascript">var use_utterance = true;</script>
<section class="post-comments">
{% from 'partials/utterances_scripts.html' import comments_script_utterances with context %}
{{ comments_script_utterances(UTTERANCES_REPO, identifier, UTTERANCES_LABEL, UTTERANCES_THEME) }}
</section>
{% endif %}

<aside class="post-nav">
Expand Down
5 changes: 4 additions & 1 deletion templates/base.html
Expand Up @@ -141,6 +141,9 @@
{% endfor %}
{% endif %}
{% include 'partials/analytics.js' %}
{% include 'partials/disqus.js' %}

{% if DISQUS_SITENAME %}
{% include 'partials/disqus.js' %}
{% endif %}
</body>
</html>
17 changes: 17 additions & 0 deletions templates/partials/_defaults.html
@@ -0,0 +1,17 @@
{% 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 %}
10 changes: 10 additions & 0 deletions templates/partials/utterances_scripts.html
@@ -0,0 +1,10 @@
{% macro comments_script_utterances(repo, id, label, theme) %}
<script src="https://utteranc.es/client.js"
data-repo="{{ repo }}"
data-issue-term="{{ id }}"
data-label="{{ label }}"
data-theme="{{ theme }}"
crossorigin="anonymous"
async>
</script>
{% endmacro %}

0 comments on commit 2367068

Please sign in to comment.