這裏有這麼多好文章,不用鼓勵一下嗎!
現代人已經脫離不了各種社群媒體,一定要在各種時事新聞底下留言刷個存在感,或者寫一些幹話讓人會心一笑 XD
Hugo 內建就有對應能用 Disqus 來做留言功能溜
申請 Disqus 的方式應該不難,就自行申請溜:官網在這
申請完帳號後,會得到一個 Shortname 這會用來對應 Hugo 的參數。
設定 Hugo 變數
config.yml
disqusShortname: xxxxxxxxxxxxxxx
# 啟用留言功能
params:
comments: true
設定留言板塊
這邊參考官方的範例就好:Conditional Loading of Disqus Comments
layouts/partials/comments.html
<div id="disqus_thread"></div>
<script type="text/javascript">
(function() {
// Don't ever inject Disqus on localhost--it creates unwanted
// discussions from 'localhost:1313' on your Disqus account...
if (window.location.hostname == "localhost")
return;
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
var disqus_shortname = '{{ .Site.DisqusShortname }}';
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com/" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
測試看看
將留言版面中執行環境的判斷註解
記得測試完畢,上線前要打開喔
if (window.location.hostname == "localhost")
//return;