Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tpl
diff options
context:
space:
mode:
authorYihui Xie <xie@yihui.name>2017-06-27 14:40:01 +0300
committerAnthony Fok <foka@debian.org>2017-06-27 14:40:01 +0300
commit2e1e4934b60ce8081a7f3a79191ed204f3098481 (patch)
tree0617b826f7bec711282f9efa0d07a4b45649cad1 /tpl
parenta54404968a4b36579797f2e7ff7f5eada94866d9 (diff)
tpl: Improve the built-in Disqus template (#3639)
* Improve the built-in Disqus template Set `disqus_identifier`, `disqus_title`, and `disqus_url` only if the user has explicitly provided them. Do not load Disqus when the website is previewed locally, otherwise it is very confusing. * Use disqus_config instead of three global variables https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
Diffstat (limited to 'tpl')
-rw-r--r--tpl/tplimpl/template_embedded.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/tpl/tplimpl/template_embedded.go b/tpl/tplimpl/template_embedded.go
index fb5ce71e9..1e5d246de 100644
--- a/tpl/tplimpl/template_embedded.go
+++ b/tpl/tplimpl/template_embedded.go
@@ -167,14 +167,18 @@ func (t *templateHandler) embedTemplates() {
t.addInternalTemplate("", "disqus.html", `{{ if .Site.DisqusShortname }}<div id="disqus_thread"></div>
<script type="text/javascript">
- var disqus_shortname = '{{ .Site.DisqusShortname }}';
- var disqus_identifier = '{{with .GetParam "disqus_identifier" }}{{ . }}{{ else }}{{ .Permalink }}{{end}}';
- var disqus_title = '{{with .GetParam "disqus_title" }}{{ . }}{{ else }}{{ .Title }}{{end}}';
- var disqus_url = '{{with .GetParam "disqus_url" }}{{ . | html }}{{ else }}{{ .Permalink }}{{end}}';
-
+ var disqus_config = function () {
+ {{with .GetParam "disqus_identifier" }}this.page.identifier = '{{ . }}';{{end}}
+ {{with .GetParam "disqus_title" }}this.page.title = '{{ . }}';{{end}}
+ {{with .GetParam "disqus_url" }}this.page.url = '{{ . | html }}';{{end}}
+ };
(function() {
+ if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
+ document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
+ return;
+ }
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
- dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
+ dsq.src = '//' + {{ .Site.DisqusShortname }} + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>