Skip to content

Commit

Permalink
Update Disqus comments implementation notes (#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring authored Jun 17, 2024
1 parent aac3c02 commit f4c1a8c
Showing 1 changed file with 0 additions and 34 deletions.
34 changes: 0 additions & 34 deletions content/en/templates/embedded.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,40 +55,6 @@ You can also set the following in the front matter for a given piece of content:
- `disqus_title`
- `disqus_url`

### Conditional loading of Disqus comments

Users have noticed that enabling Disqus comments when running the Hugo web server on `localhost` (i.e. via `hugo server`) causes the creation of unwanted discussions on the associated Disqus account.

You can create the following `layouts/partials/disqus.html`:

{{< code file=layouts/partials/disqus.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.Config.Services.Disqus.Shortname }}';
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>
{{< /code >}}

The `if` statement skips the initialization of the Disqus comment injection when you are running on `localhost`.

You can then render your custom Disqus partial template as follows:

```go-html-template
{{ partial "disqus.html" . }}
```

## Google Analytics

{{% note %}}
Expand Down

0 comments on commit f4c1a8c

Please sign in to comment.