github.com/lyeb/hugo@v0.47.1/docs/content/en/templates/internal.md (about)

     1  ---
     2  title: Internal Templates
     3  linktitle: Internal Templates
     4  description: Hugo ships with a group of boilerplate templates that cover the most common use cases for static websites.
     5  date: 2017-03-06
     6  publishdate: 2017-03-06
     7  lastmod: 2017-03-06
     8  categories: [templates]
     9  keywords: [internal, analytics,]
    10  menu:
    11    docs:
    12      parent: "templates"
    13      weight: 168
    14  weight: 168
    15  sections_weight: 168
    16  draft: false
    17  aliases: []
    18  toc: true
    19  wip: true
    20  ---
    21  <!-- reference: https://discourse.gohugo.io/t/lookup-order-for-partials/5705/6
    22  code: https://github.com/gohugoio/hugo/blob/e445c35d6a0c7f5fc2f90f31226cd1d46e048bbc/tpl/template_embedded.go#L147 -->
    23  
    24  {{% warning %}}
    25  While the following internal templates are called similar to partials, they do *not* observe the partial template lookup order.
    26  {{% /warning %}}
    27  
    28  ## Google Analytics
    29  
    30  Hugo ships with internal templates for Google Analytics tracking, including both synchronous and asynchronous tracking codes.
    31  
    32  ### Configure Google Analytics
    33  
    34  Provide your tracking id in your configuration file:
    35  
    36  {{< code-toggle file="config" >}}
    37  googleAnalytics = "UA-123-45"
    38  {{</ code-toggle >}}
    39  
    40  ### Use the Google Analytics Template
    41  
    42  You can then include the Google Analytics internal template:
    43  
    44  ```
    45  {{ template "_internal/google_analytics.html" . }}
    46  ```
    47  
    48  
    49  ```
    50  {{ template "_internal/google_analytics_async.html" . }}
    51  ```
    52  
    53  ## Disqus
    54  
    55  Hugo also ships with an internal template for [Disqus comments][disqus], a popular commenting system for both static and dynamic websites. In order to effectively use Disqus, you will need to secure a Disqus "shortname" by [signing up for the free service][disqussignup].
    56  
    57  ### Configure Disqus
    58  
    59  To use Hugo's Disqus template, you first need to set a single value in your site's `config.toml` or `config.yml`:
    60  
    61  {{< code-toggle file="config" >}}
    62  disqusShortname = "yourdiscussshortname"
    63  {{</ code-toggle >}}
    64  
    65  You also have the option to set the following in the front matter for a given piece of content:
    66  
    67  * `disqus_identifier`
    68  * `disqus_title`
    69  * `disqus_url`
    70  
    71  ### Use the Disqus Template
    72  
    73  To add Disqus, include the following line in templates where you want your comments to appear:
    74  
    75  ```
    76  {{ template "_internal/disqus.html" . }}
    77  ```
    78  
    79  ### Conditional Loading of Disqus Comments
    80  
    81  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.
    82  
    83  You can create the following `layouts/partials/disqus.html`:
    84  
    85  {{< code file="layouts/partials/disqus.html" download="disqus.html" >}}
    86  <div id="disqus_thread"></div>
    87  <script type="text/javascript">
    88  
    89  (function() {
    90      // Don't ever inject Disqus on localhost--it creates unwanted
    91      // discussions from 'localhost:1313' on your Disqus account...
    92      if (window.location.hostname == "localhost")
    93          return;
    94  
    95      var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
    96      var disqus_shortname = '{{ .Site.DisqusShortname }}';
    97      dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
    98      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    99  })();
   100  </script>
   101  <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
   102  <a href="http://disqus.com/" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
   103  {{< /code >}}
   104  
   105  The `if` statement skips the initialization of the Disqus comment injection when you are running on `localhost`.
   106  
   107  You can then render your custom Disqus partial template as follows:
   108  
   109  ```
   110  {{ partial "disqus.html" . }}
   111  ```
   112  
   113  ## The Internal Templates
   114  
   115  * `_internal/disqus.html`
   116  * `_internal/google_news.html`
   117  * `_internal/google_analytics.html`
   118  * `_internal/google_analytics_async.html`
   119  * `_internal/opengraph.html`
   120  * `_internal/pagination.html`
   121  * `_internal/schema.html`
   122  * `_internal/twitter_cards.html`
   123  
   124  [disqus]: https://disqus.com
   125  [disqussignup]: https://disqus.com/profile/signup/