Skip to content

Render comments via platform-agnostic inclusion #886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ The title for this section is `Posts` by default and rendered with an `<h2>` tag

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.

- `disqus_comments.html` &mdash; Code to markup disqus comment box.
- `comments.html` &mdash; Markup to render comments (via Disqus; active only when Jekyll environment is set to `production`).
- `footer.html` &mdash; Defines the site's footer section.
- `google-analytics.html` &mdash; Inserts Google Analytics module (active only in production environment).
- `head.html` &mdash; Code-block that defines the `<head></head>` in *default* layout.
Expand Down Expand Up @@ -272,22 +272,20 @@ You can *add* custom metadata to the `<head />` of your layouts by creating a fi

### Enabling comments (via Disqus)

Optionally, if you have a Disqus account, you can tell Jekyll to use it to show a comments section below each post.

:warning: `url`, e.g. `https://example.com`, must be set in you config file for Disqus to work.

To enable it, after setting the url field, you also need to add the following lines to your Jekyll site:
Optionally, if you have a Disqus account, you can render a comments section below each post with the following configuration:

```yaml
disqus:
shortname: my_disqus_shortname
url: "https://my_domain.com"
disqus:
shortname: my_disqus_shortname
```

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

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

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.
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.

### Author Metadata

Expand Down
17 changes: 17 additions & 0 deletions _includes/comments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% if site.disqus.shortname -%}
<script>
var disqus_config = function () {
this.page.url = '{{ page.url | absolute_url }}';
this.page.identifier = '{{ page.id }}';
};
(function() {
var d = document, s = d.createElement('script');
s.src = 'https://{{ site.disqus.shortname }}.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>
Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
</noscript>
{% endif -%}
20 changes: 0 additions & 20 deletions _includes/disqus_comments.html

This file was deleted.

12 changes: 9 additions & 3 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ <h1 class="post-title p-name" itemprop="name headline">{{ page.title | escape }}
{{ content }}
</div>

{%- if site.disqus.shortname -%}
{%- include disqus_comments.html -%}
{%- endif -%}
{% if jekyll.environment == 'production' -%}
{% if page.comments == false -%}
<div class="comments-disabled-message">
Comments have been disabled for this post.
</div>
{% else -%}
{%- include comments.html -%}
{% endif -%}
{% endif -%}

<a class="u-url" href="{{ page.url | relative_url }}" hidden></a>
</article>
1 change: 1 addition & 0 deletions _posts/2016-05-20-my-example-post.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: post
author: John Doe
comments: false
---

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.
Expand Down
5 changes: 4 additions & 1 deletion _sass/minima/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@
.post-authors { margin-top: 3px }
}


.post-title,
.post-content h1 {
margin-bottom: 10px;
Expand Down Expand Up @@ -306,6 +305,10 @@
}
}

.comments-disabled-message {
text-align: center;
font-weight: 300;
}

.social-media-list {
display: table;
Expand Down