Skip to main content

【Jekyll】 Blog Disqus 留言板

· 2 min read
Yan-Ying Liao

靜態網頁如果要新增留言板,要用到後端的語言,如PHP & MySQL,使用現成的工具Disqus可以很快的搞定留言功能:

  1. Sign up for Disqus.
  2. Copy Disqus' Universal Code.
  3. Paste the code to post.html in _layouts folder. Take this blog for example:
{% raw %}
{% if page.comments %}
<div id="disqus_thread"></div>
<script>

/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
/*
var disqus_config = function () {
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://https-noworneverev-github-io.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 %}

{% endraw %}

4. Add a variable called comments to the YAML Front Matter and set its value to true. Take this post for example:

---
layout: post
title: "【Jekyll】 Blog Disqus 留言板"
date: 2017-04-22 14:34
icon: code
comments: true
---

Now the visitors can discuss through Disqus message board.