目录

Hugo博客集成Disqus评论

Hugo博客集成Disqus评论

Hugo 包含 Disqus 的嵌入式模板,Disqus 是一种流行的评论系统,适用于静态和动态网站。要有效使用 Disqus,注册免费服务获得 Disqus “shortname”。

注册完成后,进入站点配置https://you-shortname.disqus.com/admin/settings/install/

在 “Choose a platform” 选择博客的平台类型,对于 hugo 我们选择页面最下面的 “Universal Code”:

image-20250407163627331

往下翻,然后拿到Place the following code where you'd like Disqus to load部分的代码内容

image-20250407170055379

layouts 创建 partials 再创建 comments.html 文件 vim layouts/partials/comments.html

mkdir -p layouts/partials
vim layouts/partials/comments.html

文件内容为:

<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://you-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>

修改hugo.toml文件 vim hugo.toml

# 这里修改为你自己的
disqusShortname= "you-shortname"