Skip to content

Commit 17714d1

Browse files
authored
Render comments via platform-agnostic inclusion (#886)
Merge pull request 886
1 parent 455b473 commit 17714d1

File tree

6 files changed

+38
-33
lines changed

6 files changed

+38
-33
lines changed

README.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ The title for this section is `Posts` by default and rendered with an `<h2>` tag
104104

105105
Refers to snippets of code within the `_includes` directory that can be inserted in multiple layouts (and another include-file as well) within the same theme-gem.
106106

107-
- `disqus_comments.html` &mdash; Code to markup disqus comment box.
107+
- `comments.html` &mdash; Markup to render comments (via Disqus; active only when Jekyll environment is set to `production`).
108108
- `footer.html` &mdash; Defines the site's footer section.
109109
- `google-analytics.html` &mdash; Inserts Google Analytics module (active only in production environment).
110110
- `head.html` &mdash; Code-block that defines the `<head></head>` in *default* layout.
@@ -272,22 +272,20 @@ You can *add* custom metadata to the `<head />` of your layouts by creating a fi
272272
273273
### Enabling comments (via Disqus)
274274
275-
Optionally, if you have a Disqus account, you can tell Jekyll to use it to show a comments section below each post.
276-
277-
:warning: `url`, e.g. `https://example.com`, must be set in you config file for Disqus to work.
278-
279-
To enable it, after setting the url field, you also need to add the following lines to your Jekyll site:
275+
Optionally, if you have a Disqus account, you can render a comments section below each post with the following configuration:
280276
281277
```yaml
282-
disqus:
283-
shortname: my_disqus_shortname
278+
url: "https://my_domain.com"
279+
disqus:
280+
shortname: my_disqus_shortname
284281
```
285282

286283
You can find out more about Disqus' shortnames [here](https://help.disqus.com/installation/whats-a-shortname).
287284

288285
Comments are enabled by default and will only appear in production, i.e., `JEKYLL_ENV=production`
289286

290-
If you don't want to display comments for a particular post you can disable them by adding `comments: false` to that post's YAML Front Matter.
287+
If you don't want to display comments for a particular post you can disable them by adding `comments: false` to that
288+
post's YAML Front Matter.
291289

292290
### Author Metadata
293291

_includes/comments.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{% if site.disqus.shortname -%}
2+
<script>
3+
var disqus_config = function () {
4+
this.page.url = '{{ page.url | absolute_url }}';
5+
this.page.identifier = '{{ page.id }}';
6+
};
7+
(function() {
8+
var d = document, s = d.createElement('script');
9+
s.src = 'https://{{ site.disqus.shortname }}.disqus.com/embed.js';
10+
s.setAttribute('data-timestamp', +new Date());
11+
(d.head || d.body).appendChild(s);
12+
})();
13+
</script>
14+
<noscript>
15+
Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
16+
</noscript>
17+
{% endif -%}

_includes/disqus_comments.html

-20
This file was deleted.

_layouts/post.html

+9-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@ <h1 class="post-title p-name" itemprop="name headline">{{ page.title | escape }}
3636
{{ content }}
3737
</div>
3838

39-
{%- if site.disqus.shortname -%}
40-
{%- include disqus_comments.html -%}
41-
{%- endif -%}
39+
{% if jekyll.environment == 'production' -%}
40+
{% if page.comments == false -%}
41+
<div class="comments-disabled-message">
42+
Comments have been disabled for this post.
43+
</div>
44+
{% else -%}
45+
{%- include comments.html -%}
46+
{% endif -%}
47+
{% endif -%}
4248

4349
<a class="u-url" href="{{ page.url | relative_url }}" hidden></a>
4450
</article>

_posts/2016-05-20-my-example-post.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
layout: post
33
author: John Doe
4+
comments: false
45
---
56

67
Eos eu docendi tractatos sapientem, brute option menandri in vix, quando vivendo accommodare te ius. Nec melius fastidii constituam id, viderer theophrastus ad sit, hinc semper periculis cum id. Noluisse postulant assentior est in, no choro sadipscing repudiandae vix. Vis in euismod delenit dignissim. Ex quod nostrum sit, suas decore animal id ius, nobis solet detracto quo te.

_sass/minima/_layout.scss

+4-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@
259259
.post-authors { margin-top: 3px }
260260
}
261261

262-
263262
.post-title,
264263
.post-content h1 {
265264
margin-bottom: 10px;
@@ -306,6 +305,10 @@
306305
}
307306
}
308307

308+
.comments-disabled-message {
309+
text-align: center;
310+
font-weight: 300;
311+
}
309312

310313
.social-media-list {
311314
display: table;

0 commit comments

Comments
 (0)