mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-15 14:34:47 -04:00
Update Disqus comments implementation notes (#2631)
This commit is contained in:
parent
aac3c02799
commit
f4c1a8ce1e
@ -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 %}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user