Skip to content

Instantly share code, notes, and snippets.

@NoahDragon
Forked from ythecombinator/add_disqus_hexo.md
Created April 30, 2016 00:28
Show Gist options
  • Save NoahDragon/b2d8b0adbace98d0f8296ad971a58bea to your computer and use it in GitHub Desktop.
Save NoahDragon/b2d8b0adbace98d0f8296ad971a58bea to your computer and use it in GitHub Desktop.
Simple tip for adding "Disqus" comments for Hexo.

In the footer of your theme (something like footer.ejs) you should add Disqus script:

<% if (config.disqus_shortname){ %>
<script>
  var disqus_shortname = '<%= config.disqus_shortname %>';
  <% if (page.permalink){ %>
  var disqus_url = '<%= config.url +"/"+ page.path %>';
  <% } %>
  (function(){
    var dsq = document.createElement('script');
    dsq.type = 'text/javascript';
    dsq.async = true;
    dsq.src = '//' + disqus_shortname + '.disqus.com/<% if (page.comments) { %>embed.js<% } else { %>count.js<% } %>';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
</script>
<% } %>

Don't forget that Hexo is prepared to use Disqus, so you the another missing thing is to enable it in your _config.yml

# Disqus
disqus_shortname: username
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment