]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
hugolib: Deprecate .Site.DisqusShortname
authorJoe Mooring <joe.mooring@veriphor.com>
Mon, 16 Oct 2023 17:56:37 +0000 (10:56 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 18 Oct 2023 15:35:54 +0000 (17:35 +0200)
Use .Site.Config.Services.Disqus.Shortname instead.

docs/content/en/content-management/comments.md
docs/content/en/templates/internal.md
docs/content/en/variables/site.md
hugolib/site_new.go
resources/page/site.go
tpl/tplimpl/embedded/templates/disqus.html

index df9453c484d08f39e25694a3e1c827444837ddc6..39663013b6b0964a567f6c9d0e29f4b0c86a66a3 100644 (file)
@@ -24,8 +24,9 @@ Hugo comes with all the code you need to load Disqus into your templates. Before
 
 Disqus comments require you set a single value in your [site's configuration file][configuration] like so:
 
-{{< code-toggle copy=false >}}
-disqusShortname = "yourDisqusShortname"
+{{< code-toggle file="hugo" >}}
+[services.disqus]
+shortname = 'your-disqus-shortname'
 {{</ code-toggle >}}
 
 For many websites, this is enough configuration. However, you also have the option to set the following in the [front matter] of a single content file:
index 52e846007b238b61b0b16bf3abfbd9d1a32db370..9118184e8dabac0f8cd887408708d6501321b569 100644 (file)
@@ -55,9 +55,16 @@ Hugo also ships with an internal template for [Disqus comments][disqus], a popul
 To use Hugo's Disqus template, first set up a single configuration value:
 
 {{< code-toggle file="hugo" >}}
-disqusShortname = "your-disqus-shortname"
+[services.disqus]
+shortname = 'your-disqus-shortname'
 {{</ code-toggle >}}
 
+Hugo's Disqus template accesses this value with:
+
+```go-html-template
+{{ .Site.Config.Services.Disqus.Shortname }}
+```
+
 You can also set the following in the front matter for a given piece of content:
 
 * `disqus_identifier`
@@ -72,8 +79,6 @@ To add Disqus, include the following line in the templates where you want your c
 {{ template "_internal/disqus.html" . }}
 ```
 
-A `.Site.DisqusShortname` variable is also exposed from the configuration.
-
 ### 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.
@@ -91,7 +96,7 @@ You can create the following `layouts/partials/disqus.html`:
         return;
 
     var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
-    var disqus_shortname = '{{ .Site.DisqusShortname }}';
+    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);
 })();
index 4605b9a429ce925329476757ffce16421120c0fe..55e9a75128b0b36e8f5cbc377eb0655de7459311 100644 (file)
@@ -35,9 +35,6 @@ All the methods below, e.g. `.Site.RegularPages` can also be reached via the glo
 .Site.Data
 : custom data, see [Data Templates](/templates/data-templates/).
 
-.Site.DisqusShortname
-: a string representing the shortname of the Disqus shortcode as defined in the site configuration.
-
 .Site.Home
 : reference to the homepage's [page object](/variables/page/)
 
index d582b1b7922d1ee9f3935d37acd6bb7afa71f990..b35de79ef28be3e44759795089be4ebd3161631b 100644 (file)
@@ -447,8 +447,9 @@ func (s *Site) Social() map[string]string {
        return s.conf.Social
 }
 
-// TODO(bep): deprecate.
+// Deprecated: Use .Site.Config.Services.Disqus.Shortname instead
 func (s *Site) DisqusShortname() string {
+       helpers.Deprecated(".Site.DisqusShortname", "Use .Site.Config.Services.Disqus.Shortname instead.", false)
        return s.Config().Services.Disqus.Shortname
 }
 
index 527bc504675195ba29b97ec184c42656ece2b3b3..ba2759a06188157934242bd8339171baa19368d1 100644 (file)
@@ -298,6 +298,7 @@ func (s *siteWrapper) IsMultiLingual() bool {
        return s.s.IsMultiLingual()
 }
 
+// Deprecated: Use .Site.Config.Services.Disqus.Shortname instead
 func (s *siteWrapper) DisqusShortname() string {
        return s.s.DisqusShortname()
 }
@@ -440,6 +441,7 @@ func (testSite) GetPageWithTemplateInfo(info tpl.Info, ref ...string) (Page, err
        return nil, nil
 }
 
+// Deprecated: Use .Site.Config.Services.Disqus.Shortname instead
 func (testSite) DisqusShortname() string {
        return ""
 }
index ca5118608a38a2b6b08d621cc9a4a88e79ff67bf..d90a525864c5e71f898e0bf61726a7007f51e8be 100644 (file)
@@ -1,6 +1,6 @@
 {{- $pc := .Site.Config.Privacy.Disqus -}}
 {{- if not $pc.Disable -}}
-{{ if .Site.DisqusShortname }}<div id="disqus_thread"></div>
+{{ if .Site.Config.Services.Disqus.Shortname }}<div id="disqus_thread"></div>
 <script type="application/javascript">
     window.disqus_config = function () {
     {{with .Params.disqus_identifier }}this.page.identifier = '{{ . }}';{{end}}
             return;
         }
         var d = document, s = d.createElement('script'); s.async = true;
-        s.src = '//' + {{ .Site.DisqusShortname }} + '.disqus.com/embed.js';
+        s.src = '//' + {{ .Site.Config.Services.Disqus.Shortname }} + '.disqus.com/embed.js';
         s.setAttribute('data-timestamp', +new Date());
         (d.head || d.body).appendChild(s);
     })();
 </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>{{end}}
-{{- end -}}
\ No newline at end of file
+{{- end -}}