Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 1.25 KB

adding-disqus-comments-to-item-pages.md

File metadata and controls

36 lines (26 loc) · 1.25 KB

How to add Disqus comments to item pages

Getting a shortname from Disqus

Before proceeding, make sure that you've registered a Disqus shortname, as this will be used to reference all of your comments and settings.

Once you've got your shortname, you can proceed with the next steps.

JavaScript

Create a new file called disqus.js in your Resources folder and paste this code within that file:

(function() {
    var t = document,
        e = t.createElement("script");
    e.src = "https://REPLACE-WITH-SHORTNAME.disqus.com/embed.js", e.setAttribute("data-timestamp", +new Date), (t.head || t.body).appendChild(e)
})();

Don't forget to replace REPLACE-WITH-SHORTNAME with your shortname.

Swift

In your theme file add the following code to your makeItemHTML function. This ensures that comment threads are only shown on item pages:

func makeItemHTML(for item: Item<Site>,
                  context: PublishingContext<Site>) throws -> HTML {
    ...
    .div(.id("disqus_thread")),
    .script(.src("/disqus.js")),
    .element(named: "noscript", text: "Please enable JavaScript to view the comments")
    ...
}