Add Disqus to Jekyll Minima Theme Simplified
source link: https://cuda-chen.github.io/blogging/2020/03/28/add-Disqus-to-Jekyll-Minima-theme-simplified.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Add Disqus to Jekyll Minima Theme Simplified
Mar 28, 2020
Some of the Jekyll theme lack of comment system, as a result, we have to add plugin to fulfill this task, and Disqus is recommended by many people because of its simplicity to install on your website. However, some of the themes have some problems adding Disqus, so I write this guide to teach you Minima users to install Disqus with no any problem.
Let’s get started!
First create a Disqus account.
Then set your Jekyll website with Disqus by creating a unique Disqus shortname.
After setting your Disqus shortname, open your Jekyll sites _config.yml
and add the
following code. Note that you have to alter my_disqus_shortname
to your Disqus
shortname you set.
# Disqus Comments
disqus:
# Leave shortname blank to disable comments site-wide.
# Disable comments for any post by adding `comments: false` to that post's YAML Front Matter.
shortname: my_disqus_shortname
url: my_website_url
Mentioned in this issue, you have to explicitly add
the url
placeholder if you are using Minima theme just like me.
Next, create a file named disqus_comments.html
in your Jekyll’s _includes
directory, and add
the following content in the file:
{% if page.comments != false and jekyll.environment == "production" %}
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = '{{ page.url | absolute_url }}';
this.page.identifier = '{{ page.url | absolute_url }}';
};
(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" rel="nofollow">comments powered by Disqus.</a></noscript>
{% endif %}
The above code block is called Disqus Universal Embed Code.
Note this code {% if page.comments != false and jekyll.environment == "production" %}
and
{% endif %}
.
You simply add comments: false
on any blog post YAML front-matter
if you want to disable Disqus comments. Additionally, it will prevent Disqus loading when
the environment of Jekyll is set to development
.
At last, open your post layout file usually called post.html
in your _layouts
directory
and add the following liquid code just after the </article>
tag. This tells Jekyll to
load Disqus comments when your Jekyll environment is set to production
.
{% if site.disqus.shortname %}
{% include disqus_comments.html %}
{% endif %}
You can check the settings are effective or not by typing this command in your terminal:
$ JEKYLL_ENV=production bundle exec jekyll serve
That’s all! After pushing these changes to your live site, the Disqus comment system ought to work in no problem.
Reference
https://desiredpersona.com/disqus-comments-jekyll/
Recommend
-
86
How and why we moved from Disqus to schnack, a self-hostable Open Source commenting platform.
-
63
isso - a Disqus alternative
-
12
Add Google Analytics to Jekyll Minima Theme Simplified May 3, 2020 So you want to get some statistics about your blog, but you don’t want to install any plugins because you are too lazy and afra...
-
150
How to Add a Copy-to-Clipboard Button to Jekyll I’m always looking for ways to improve my site’s user experience without toppling the precarious house of cards that is cross-browser compatibility. And one thing that...
-
12
Optimization of multiple parameters with many local minima advertisements I'm looking for algorithms to find a "best" set of parameter values....
-
5
2021-10-26 14:21 去中心化协议Minima完成650万美元A轮融资,GSR等参投 据Cryptodaily消息,去中心化协议Minima完成650万美元A轮融资,GSR、DEX Ventures、AGE Crypto、SMO Capital、Vinny Lingham...
-
9
Minima Closes Series A Round Raising $6.5M to Build ‘The Most Decentralized Network’ October 26, 2021 ZUG, Switzerland, 26th October, 2021,
-
5
Announcing SpaacedOut Gem Jekyll Theme v1.2.x Oct 28, 2021 ● Permalink ●
-
6
Minima Accelerates Towards Mainnet, With More Than Half of Bitcoin’s Full Node Count November 15, 2021 ZUG, Switzerland, 15th November, 2021, —
-
5
Switch Your Jekyll Blog to Google Analytics 4 Simplified Apr 30, 2022 Introduction As a reminder from Google [^1]. Google Analytics w...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK