mirror of
https://github.com/tiennm99/hugoDocs.git
synced 2026-10-13 08:15:37 +00:00
Cleanup action delimiters
This commit is contained in:
1 parent
cc96070f06
commit
7bee3e4c14
33 files changed
+157
-157
No files matched your search
@@ -344,7 +344,7 @@ The function will read `.Count` from `.ReadingTime` and evaluate whether the num
|
||||
{{< code-toggle file="i18n/en-US" >}}
|
||||
[readingTime]
|
||||
one = "One minute to read"
|
||||
other = "{{.Count }} minutes to read"
|
||||
other = "{{ .Count }} minutes to read"
|
||||
{{< /code-toggle >}}
|
||||
|
||||
Assuming `.ReadingTime.Count` in the context has value is 525600. The result will be:
|
||||
|
||||
@@ -185,7 +185,7 @@ This shortcode will convert the source code provided into syntax-highlighted HTM
|
||||
<div>
|
||||
<h1 id="title">{{ .Title }}</h1>
|
||||
{{ range .Pages }}
|
||||
{{ .Render "summary"}}
|
||||
{{ .Render "summary" }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -14,7 +14,7 @@ aliases: [/extras/toc/]
|
||||
|
||||
{{% note "TOC Heading Levels are Fixed" %}}
|
||||
|
||||
Previously, there was no out-of-the-box way to specify which heading levels you want the TOC to render. [See the related GitHub discussion (#1778)](https://github.com/gohugoio/hugo/issues/1778). As such, the resulting `<nav id="TableOfContents"><ul></ul></nav>` was going to start at `<h1>` when pulling from `{{.Content }}`.
|
||||
Previously, there was no out-of-the-box way to specify which heading levels you want the TOC to render. [See the related GitHub discussion (#1778)](https://github.com/gohugoio/hugo/issues/1778). As such, the resulting `<nav id="TableOfContents"><ul></ul></nav>` was going to start at `<h1>` when pulling from `{{ .Content }}`.
|
||||
|
||||
Hugo [v0.60.0](https://github.com/gohugoio/hugo/releases/tag/v0.60.0) made a switch to [Goldmark](https://github.com/yuin/goldmark/) as the default library for Markdown which has improved and configurable implementation of TOC. Take a look at [how to configure TOC](/getting-started/configuration-markup/#table-of-contents) for Goldmark renderer.
|
||||
|
||||
@@ -72,15 +72,15 @@ The following is a [partial template][partials] that adds slightly more logic fo
|
||||
{{ if and (gt .WordCount 400 ) (.Params.toc) }}
|
||||
<aside>
|
||||
<header>
|
||||
<h2>{{.Title }}</h2>
|
||||
<h2>{{ .Title }}</h2>
|
||||
</header>
|
||||
{{.TableOfContents }}
|
||||
{{ .TableOfContents }}
|
||||
</aside>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
{{% note %}}
|
||||
With the preceding example, even pages with > 400 words *and* `toc` not set to `false` will not render a table of contents if there are no headings in the page for the `{{.TableOfContents }}` variable to pull from.
|
||||
With the preceding example, even pages with > 400 words *and* `toc` not set to `false` will not render a table of contents if there are no headings in the page for the `{{ .TableOfContents }}` variable to pull from.
|
||||
{{% /note %}}
|
||||
|
||||
## Usage with AsciiDoc
|
||||
|
||||
@@ -72,7 +72,7 @@ Here is a review of the front matter fields automatically generated for you usin
|
||||
`relatedfuncs`
|
||||
: other [templating functions] you feel are related to your new function to help fellow Hugo users.
|
||||
|
||||
`{{.Content }}`
|
||||
`{{ .Content }}`
|
||||
: an extended description of the new function; examples are not only welcomed but encouraged.
|
||||
|
||||
In the body of your function, expand the short description used in the front matter. Include as many examples as possible, and leverage the Hugo docs [`code` shortcode](#add-code-blocks).
|
||||
@@ -136,15 +136,15 @@ This example HTML code block tells Hugo users the following:
|
||||
<main>
|
||||
<article>
|
||||
<header>
|
||||
<h1>{{.Title }}</h1>
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ with .Params.subtitle }}
|
||||
<span>{{.}}</span>
|
||||
<span>{{ . }}</span>
|
||||
</header>
|
||||
<div>
|
||||
{{.Content }}
|
||||
{{ .Content }}
|
||||
</div>
|
||||
<aside>
|
||||
{{.TableOfContents }}
|
||||
{{ .TableOfContents }}
|
||||
</aside>
|
||||
</article>
|
||||
</main>
|
||||
@@ -161,15 +161,15 @@ The output of this example will render to the Hugo docs as follows:
|
||||
<main>
|
||||
<article>
|
||||
<header>
|
||||
<h1>{{.Title }}</h1>
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ with .Params.subtitle }}
|
||||
<span>{{.}}</span>
|
||||
<span>{{ . }}</span>
|
||||
</header>
|
||||
<div>
|
||||
{{.Content }}
|
||||
{{ .Content }}
|
||||
</div>
|
||||
<aside>
|
||||
{{.TableOfContents }}
|
||||
{{ .TableOfContents }}
|
||||
</aside>
|
||||
</article>
|
||||
</main>
|
||||
|
||||
@@ -30,24 +30,24 @@ You can use `after` in combination with the [`first` function] and Hugo's [power
|
||||
{{< code file="layouts/section/articles.html" download="articles.html" >}}
|
||||
{{ define "main" }}
|
||||
<section class="row featured-article">
|
||||
<h2>Featured Article</h2>
|
||||
{{ range first 1 .Pages.ByPublishDate.Reverse }}
|
||||
<header>
|
||||
<h3><a href="{{.Permalink }}">{{.Title }}</a></h3>
|
||||
</header>
|
||||
<p>{{.Description }}</p>
|
||||
{{ end }}
|
||||
<h2>Featured Article</h2>
|
||||
{{ range first 1 .Pages.ByPublishDate.Reverse }}
|
||||
<header>
|
||||
<h3><a href="{{ . Permalink }}">{{ .Title }}</a></h3>
|
||||
</header>
|
||||
<p>{{ .Description }}</p>
|
||||
{{ end }}
|
||||
</section>
|
||||
<div class="row recent-articles">
|
||||
<h2>Recent Articles</h2>
|
||||
{{ range first 3 (after 1 .Pages.ByPublishDate.Reverse) }}
|
||||
<section class="recent-article">
|
||||
<header>
|
||||
<h3><a href="{{.Permalink }}">{{.Title }}</a></h3>
|
||||
</header>
|
||||
<p>{{.Description }}</p>
|
||||
</section>
|
||||
{{ end }}
|
||||
<h2>Recent Articles</h2>
|
||||
{{ range first 3 (after 1 .Pages.ByPublishDate.Reverse) }}
|
||||
<section class="recent-article">
|
||||
<header>
|
||||
<h3><a href="{{ .Permalink }}">{{ .Title }}</a></h3>
|
||||
</header>
|
||||
<p>{{ .Description }}</p>
|
||||
</section>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
@@ -16,5 +16,5 @@ relatedfuncs: [truncate]
|
||||
Useful in a pipeline to remove newlines added by other processing (e.g., [`markdownify`](/functions/markdownify/)).
|
||||
|
||||
```go-html-template
|
||||
{{ chomp "<p>Blockhead</p>\n"}} → "<p>Blockhead</p>"
|
||||
{{ chomp "<p>Blockhead</p>\n" }} → "<p>Blockhead</p>"
|
||||
```
|
||||
@@ -71,13 +71,13 @@ The following have equivalent return values but are far less terse. This demonst
|
||||
Using `if`:
|
||||
|
||||
{{< code file="if-instead-of-default.html" copy="false" >}}
|
||||
<title>{{ if .Params.seo_title }}{{.Params.seo_title }}{{ else }}{{.Title }}{{ end }}</title>
|
||||
<title>{{ if .Params.seo_title }}{{ .Params.seo_title }}{{ else }}{{ .Title }}{{ end }}</title>
|
||||
=> Sane Defaults
|
||||
{{< /code >}}
|
||||
|
||||
Using `with`:
|
||||
|
||||
{{< code file="with-instead-of-default.html" copy="false" >}}
|
||||
<title>{{ with .Params.seo_title }}{{.}}{{ else }}{{.Title }}{{ end }}</title>
|
||||
<title>{{ with .Params.seo_title }}{{ . }}{{ else }}{{ .Title }}{{ end }}</title>
|
||||
=> Sane Defaults
|
||||
{{< /code >}}
|
||||
@@ -89,7 +89,7 @@ An example table listing the dependencies:
|
||||
{{ range $index, $element := hugo.Deps }}
|
||||
<tr>
|
||||
<th scope="row">{{ add $index 1 }}</th>
|
||||
<td>{{ with $element.Owner }}{{.Path }}{{ end }}</td>
|
||||
<td>{{ with $element.Owner }}{{ .Path }}{{ end }}</td>
|
||||
<td>
|
||||
{{ $element.Path }}
|
||||
{{ with $element.Replace }}
|
||||
|
||||
@@ -14,8 +14,8 @@ If the input is either an int64 value or the string representation of an integer
|
||||
|
||||
|
||||
```go-html-template
|
||||
{{ humanize "my-first-post"}} → "My first post"
|
||||
{{ humanize "myCamelPost"}} → "My camel post"
|
||||
{{ humanize "52"}} → "52nd"
|
||||
{{ humanize "my-first-post" }} → "My first post"
|
||||
{{ humanize "myCamelPost" }} → "My camel post"
|
||||
{{ humanize "52" }} → "52nd"
|
||||
{{ humanize 103 }} → "103rd"
|
||||
```
|
||||
@@ -45,7 +45,7 @@ images.Text TEXT DICT)
|
||||
The following example will add the text `Hugo rocks!` to the image with the specified color, size and position.
|
||||
|
||||
```go-html-template
|
||||
{{ $img := resources.Get "/images/background.png"}}
|
||||
{{ $img := resources.Get "/images/background.png" }}
|
||||
{{ $img = $img.Filter (images.Text "Hugo rocks!" (dict
|
||||
"color" "#ffffff"
|
||||
"size" 60
|
||||
@@ -60,7 +60,7 @@ You can load a custom font if needed. Load the font as a Hugo `Resource` and set
|
||||
```go-html-template
|
||||
|
||||
{{ $font := resources.GetRemote "https://github.com/google/fonts/raw/main/apache/roboto/static/Roboto-Black.ttf" }}
|
||||
{{ $img := resources.Get "/images/background.png"}}
|
||||
{{ $img := resources.Get "/images/background.png" }}
|
||||
{{ $img = $img.Filter (images.Text "Hugo rocks!" (dict
|
||||
"font" $font
|
||||
))}}
|
||||
@@ -221,6 +221,6 @@ images.ImageConfig PATH
|
||||
|
||||
```go-html-template
|
||||
{{ with (imageConfig "favicon.ico") }}
|
||||
favicon.ico: {{.Width }} x {{.Height }}
|
||||
favicon.ico: {{ .Width }} x {{ .Height }}
|
||||
{{ end }}
|
||||
```
|
||||
@@ -17,6 +17,6 @@ Takes either a slice, array, or channel and an index or a map and a key as input
|
||||
```
|
||||
|
||||
{{% warning %}}
|
||||
All site-level configuration keys are stored as lower case. Therefore, a `myParam` key-value set in your [site configuration file](/getting-started/configuration/) needs to be accessed with `{{ if isset .Site.Params "myparam"}}` and *not* with `{{ if isset .Site.Params "myParam"}}`. Note that you can still access the same config key with `.Site.Params.myParam` *or* `.Site.Params.myparam`, for example, when using [`with`](/functions/with).
|
||||
All site-level configuration keys are stored as lower case. Therefore, a `myParam` key-value set in your [site configuration file](/getting-started/configuration/) needs to be accessed with `{{ if isset .Site.Params "myparam" }}` and *not* with `{{ if isset .Site.Params "myParam" }}`. Note that you can still access the same config key with `.Site.Params.myParam` *or* `.Site.Params.myparam`, for example, when using [`with`](/functions/with).
|
||||
This restriction also applies when accessing page-level front matter keys from within [shortcodes](/content-management/shortcodes/).
|
||||
{{% /warning %}}
|
||||
@@ -30,7 +30,7 @@ You may want to append a class to a heading according to the length of the strin
|
||||
|
||||
{{< code file="check-title-length.html" >}}
|
||||
<header>
|
||||
<h1{{ if gt (len .Title) 80 }} class="long-title"{{ end }}>{{.Title }}</h1>
|
||||
<h1{{ if gt (len .Title) 80 }} class="long-title"{{ end }}>{{ .Title }}</h1>
|
||||
</header>
|
||||
{{< /code >}}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ For example, building your site on June 24, 2017, with the following templating:
|
||||
|
||||
```go-html-template
|
||||
<div>
|
||||
<small>© {{ now.Format "2006"}}</small>
|
||||
<small>© {{ now.Format "2006" }}</small>
|
||||
</div>
|
||||
```
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ This example could render a piece of content using the content view located at `
|
||||
|
||||
```go-html-template
|
||||
{{ range .Pages }}
|
||||
{{ .Render "summary"}}
|
||||
{{ .Render "summary" }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
|
||||
@@ -10,4 +10,4 @@ signature: ["string INPUT"]
|
||||
relatedfuncs: []
|
||||
---
|
||||
|
||||
* `{{ string "BatMan"}}` → "BatMan"
|
||||
* `{{ string "BatMan" }}` → "BatMan"
|
||||
@@ -22,9 +22,9 @@ The following might be used as a partial within a [single page template][singlet
|
||||
|
||||
{{< code file="layouts/partials/content-header.html" download="content-header.html" >}}
|
||||
<header>
|
||||
<h1>{{.Title }}</h1>
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ with .Params.location }}
|
||||
<div><a href="/locations/{{ . | urlize }}">{{.}}</a></div>
|
||||
<div><a href="/locations/{{ . | urlize }}">{{ . }}</a></div>
|
||||
{{ end }}
|
||||
<!-- Creates a list of tags for the content and links to each of their pages -->
|
||||
{{ with .Params.tags }}
|
||||
|
||||
@@ -77,7 +77,7 @@ The following logical operators are available with `where`:
|
||||
When using booleans you should not put quotation marks.
|
||||
```go-html-template
|
||||
{{ range where .Pages "Draft" true }}
|
||||
<p>{{.Title }}</p>
|
||||
<p>{{ .Title }}</p>
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ The following example checks for a [user-defined site variable](/variables/site/
|
||||
|
||||
{{< code file="layouts/partials/twitter.html" >}}
|
||||
{{ with .Site.Params.twitteruser }}<span class="twitter">
|
||||
<a href="https://twitter.com/{{.}}" rel="author">
|
||||
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}"
|
||||
<a href="https://twitter.com/{{ . }}" rel="author">
|
||||
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{ . }}"
|
||||
alt="Twitter"></a>
|
||||
</span>{{ end }}
|
||||
{{< /code >}}
|
||||
@@ -19,13 +19,13 @@ See [Image Processing Options](https://gohugo.io/content-management/image-proces
|
||||
Another useful addon is the `$pages.Next` and `$pages.Prev` methods on the core page collections in Hugo. These works the same way as the built-in static variants one `Page`, e.g. `.Next` and `.NextInSection`:
|
||||
|
||||
```
|
||||
{{ with .Site.RegularPages.Next . }}{{.RelPermalink }}{{ end }}
|
||||
{{ with .Site.RegularPages.Next . }}{{ .RelPermalink }}{{ end }}
|
||||
```
|
||||
|
||||
The above is a functionally equivalent (but slightly slower) variant of:
|
||||
|
||||
```
|
||||
{{ with .Next }}{{.RelPermalink }}{{ end }}
|
||||
{{ with .Next }}{{ .RelPermalink }}{{ end }}
|
||||
```
|
||||
|
||||
See [Pages Methods](https://gohugo.io/variables/pages/) for more information.
|
||||
|
||||
@@ -61,7 +61,7 @@ Spelled-out cardinal numbers (e.g. "one", "two", and "three") and ordinal abbrev
|
||||
To continue with the example above:
|
||||
|
||||
```go-html-template
|
||||
{{.Date.Format "Jan 2nd 2006"}}
|
||||
{{ .Date.Format "Jan 2nd 2006" }}
|
||||
```
|
||||
|
||||
Hugo assumes you want to append `nd` as a string to the day of the month and outputs the following:
|
||||
|
||||
@@ -27,12 +27,12 @@ In addition to the standard page variables, the 404 page has access to all site
|
||||
This is a basic example of a 404.html template:
|
||||
|
||||
{{< code file="layouts/404.html" download="404.html" >}}
|
||||
{{ define "main"}}
|
||||
<main id="main">
|
||||
<div>
|
||||
<h1 id="title"><a href="{{ "" | relURL }}">Go Home</a></h1>
|
||||
</div>
|
||||
</main>
|
||||
{{ define "main" }}
|
||||
<main id="main">
|
||||
<div>
|
||||
<h1 id="title"><a href="{{ "" | relURL }}">Go Home</a></h1>
|
||||
</div>
|
||||
</main>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ The following shows how you can override both the `"main"` and `"title"` block a
|
||||
|
||||
{{< code file="layouts/_default/single.html" download="single.html" >}}
|
||||
{{ define "title" }}
|
||||
<!-- This will override the default value set in baseof.html; i.e., "{{.Site.Title }}" in the original example-->
|
||||
<!-- This will override the default value set in baseof.html; i.e., "{{ .Site.Title }}" in the original example-->
|
||||
{{ .Title }} – {{ .Site.Title }}
|
||||
{{ end }}
|
||||
{{ define "main" }}
|
||||
|
||||
@@ -127,7 +127,7 @@ Achievements:
|
||||
You can use the following code to render the `Short Description` in your layout:
|
||||
|
||||
```go-html-template
|
||||
<div>Short Description of {{.Site.Data.User0123.Name }}: <p>{{ index .Site.Data.User0123 "Short Description" | markdownify }}</p></div>
|
||||
<div>Short Description of {{ .Site.Data.User0123.Name }}: <p>{{ index .Site.Data.User0123 "Short Description" | markdownify }}</p></div>
|
||||
```
|
||||
|
||||
Note the use of the [`markdownify` template function][markdownify]. This will send the description through the Markdown rendering engine.
|
||||
|
||||
@@ -33,27 +33,27 @@ See the homepage template below or [Content Organization][contentorg] for more i
|
||||
|
||||
## Example Homepage Template
|
||||
|
||||
The following is an example of a homepage template that uses [partial][partials], [base] templates, and a content file at `content/_index.md` to populate the `{{.Title }}` and `{{.Content }}` [page variables][pagevars].
|
||||
The following is an example of a homepage template that uses [partial][partials], [base] templates, and a content file at `content/_index.md` to populate the `{{ .Title }}` and `{{ .Content }}` [page variables][pagevars].
|
||||
|
||||
{{< code file="layouts/index.html" download="index.html" >}}
|
||||
{{ define "main" }}
|
||||
<main aria-role="main">
|
||||
<header class="homepage-header">
|
||||
<h1>{{.Title }}</h1>
|
||||
{{ with .Params.subtitle }}
|
||||
<span class="subtitle">{{.}}</span>
|
||||
{{ end }}
|
||||
</header>
|
||||
<div class="homepage-content">
|
||||
<!-- Note that the content for index.html, as a sort of list page, will pull from content/_index.md -->
|
||||
{{.Content }}
|
||||
</div>
|
||||
<div>
|
||||
{{ range first 10 .Site.RegularPages }}
|
||||
{{ .Render "summary"}}
|
||||
{{ end }}
|
||||
</div>
|
||||
</main>
|
||||
<main aria-role="main">
|
||||
<header class="homepage-header">
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ with .Params.subtitle }}
|
||||
<span class="subtitle">{{ . }}</span>
|
||||
{{ end }}
|
||||
</header>
|
||||
<div class="homepage-content">
|
||||
<!-- Note that the content for index.html, as a sort of list page, will pull from content/_index.md -->
|
||||
{{ .Content }}
|
||||
</div>
|
||||
<div>
|
||||
{{ range first 10 .Site.RegularPages }}
|
||||
{{ .Render "summary" }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</main>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
|
||||
@@ -544,11 +544,11 @@ Here is an example of corresponding code that could be used inside a `toc.html`
|
||||
{{ if not .Params.notoc }}
|
||||
<aside>
|
||||
<header>
|
||||
<a href="#{{.Title | urlize }}">
|
||||
<h3>{{.Title }}</h3>
|
||||
<a href="#{{ .Title | urlize }}">
|
||||
<h3>{{ .Title }}</h3>
|
||||
</a>
|
||||
</header>
|
||||
{{.TableOfContents }}
|
||||
{{ .TableOfContents }}
|
||||
</aside>
|
||||
<a href="#" id="toc-toggle"></a>
|
||||
{{ end }}
|
||||
@@ -574,7 +574,7 @@ Within a footer layout, you might then declare a `<footer>` that is only rendere
|
||||
```go-html-template
|
||||
{{ if .Site.Params.copyrighthtml }}
|
||||
<footer>
|
||||
<div class="text-center">{{.Site.Params.CopyrightHTML | safeHTML }}</div>
|
||||
<div class="text-center">{{ .Site.Params.CopyrightHTML | safeHTML }}</div>
|
||||
</footer>
|
||||
{{ end }}
|
||||
```
|
||||
@@ -584,8 +584,8 @@ An alternative way of writing the "`if`" and then referencing the same value is
|
||||
{{< code file="layouts/partials/twitter.html" >}}
|
||||
{{ with .Site.Params.twitteruser }}
|
||||
<div>
|
||||
<a href="https://twitter.com/{{.}}" rel="author">
|
||||
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}" alt="Twitter"></a>
|
||||
<a href="https://twitter.com/{{ . }}" rel="author">
|
||||
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{ . }}" alt="Twitter"></a>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
@@ -597,7 +597,7 @@ Finally, you can pull "magic constants" out of your layouts as well. The followi
|
||||
<h1>Recent Posts</h1>
|
||||
<ul>
|
||||
{{- range first .Site.Params.SidebarRecentLimit .Site.Pages -}}
|
||||
<li><a href="{{.RelPermalink }}">{{.Title }}</a></li>
|
||||
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
|
||||
{{- end -}}
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
@@ -87,21 +87,21 @@ You can now access this `_index.md`'s' content in your list template:
|
||||
{{< code file="layouts/_default/list.html" download="list.html" >}}
|
||||
{{ define "main" }}
|
||||
<main>
|
||||
<article>
|
||||
<header>
|
||||
<h1>{{.Title}}</h1>
|
||||
</header>
|
||||
<!-- "{{.Content}}" pulls from the markdown content of the corresponding _index.md -->
|
||||
{{.Content}}
|
||||
</article>
|
||||
<ul>
|
||||
<article>
|
||||
<header>
|
||||
<h1>{{ .Title} }</h1>
|
||||
</header>
|
||||
<!-- "{{ .Content} }" pulls from the markdown content of the corresponding _index.md -->
|
||||
{{ .Content }}
|
||||
</article>
|
||||
<ul>
|
||||
<!-- Ranges through content/posts/*.md -->
|
||||
{{ range .Pages }}
|
||||
<li>
|
||||
<a href="{{.Permalink}}">{{.Date.Format "2006-01-02"}} | {{.Title}}</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ .Permalink }}">{{ .Date.Format "2006-01-02" }} | {{ .Title }}</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</ul>
|
||||
</main>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
@@ -128,7 +128,7 @@ This above will output the following HTML:
|
||||
|
||||
### List Pages Without `_index.md`
|
||||
|
||||
You do *not* have to create an `_index.md` file for every list page (i.e. section, taxonomy, taxonomy terms, etc) or the homepage. If Hugo does not find an `_index.md` within the respective content section when rendering a list template, the page will be created but with no `{{.Content}}` and only the default values for `.Title` etc.
|
||||
You do *not* have to create an `_index.md` file for every list page (i.e. section, taxonomy, taxonomy terms, etc) or the homepage. If Hugo does not find an `_index.md` within the respective content section when rendering a list template, the page will be created but with no `{{ .Content }}` and only the default values for `.Title` etc.
|
||||
|
||||
Using this same `layouts/_default/list.html` template and applying it to the `quotes` section above will render the following output. Note that `quotes` does not have an `_index.md` file to pull from:
|
||||
|
||||
@@ -168,7 +168,7 @@ This list template has been modified slightly from a template originally used in
|
||||
<ul>
|
||||
<!-- Renders the li.html content view for each content/posts/*.md -->
|
||||
{{ range .Pages }}
|
||||
{{ .Render "li"}}
|
||||
{{ .Render "li" }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
</div>
|
||||
@@ -185,7 +185,7 @@ This list template has been modified slightly from a template originally used in
|
||||
<h1>{{ .Title }}</h1>
|
||||
<!-- ranges through each of the content files associated with a particular taxonomy term and renders the summary.html content view -->
|
||||
{{ range .Pages }}
|
||||
{{ .Render "summary"}}
|
||||
{{ .Render "summary" }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</main>
|
||||
@@ -376,14 +376,14 @@ Hugo provides some functions for grouping pages by Section, Type, Date, etc.
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
In the above example, you may want `{{.Title}}` to point the `title` field you have added to your `_index.md` file instead. You can access this value using the [`.GetPage` function][getpage]:
|
||||
In the above example, you may want `{{ .Title }}` to point the `title` field you have added to your `_index.md` file instead. You can access this value using the [`.GetPage` function][getpage]:
|
||||
|
||||
{{< code file="layouts/partials/by-page-field.html" >}}
|
||||
<!-- Groups content according to content section.-->
|
||||
{{ range .Pages.GroupBy "Section" }}
|
||||
<!-- Checks for existence of _index.md for a section; if available, pulls from "title" in front matter -->
|
||||
{{ with $.Site.GetPage "section" .Key }}
|
||||
<h3>{{.Title}}</h3>
|
||||
<h3>{{ .Title }}</h3>
|
||||
{{ else }}
|
||||
<!-- If no _index.md is available, ".Key" defaults to the section title and filters to title casing -->
|
||||
<h3>{{ .Key | title }}</h3>
|
||||
@@ -539,7 +539,7 @@ While these are logical defaults, they are not always the desired order. There a
|
||||
|
||||
### Order Within Groups
|
||||
|
||||
Because Grouping returns a `{{.Key}}` and a slice of pages, all the ordering methods listed above are available.
|
||||
Because Grouping returns a `{{ .Key }}` and a slice of pages, all the ordering methods listed above are available.
|
||||
|
||||
Here is the ordering for the example that follows:
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ Examples:
|
||||
{{ .Content }}
|
||||
<ul class="contents">
|
||||
{{ range .Paginator.Pages }}
|
||||
<li>{{.Title }}
|
||||
<li>{{ .Title }}
|
||||
<div>
|
||||
{{ partial "summary.html" . }}
|
||||
</div>
|
||||
|
||||
@@ -209,21 +209,21 @@ You have created the shortcode at `/layouts/shortcodes/img.html`, which loads th
|
||||
|
||||
{{< code file="/layouts/shortcodes/img.html" >}}
|
||||
<!-- image -->
|
||||
<figure {{ with .Get "class" }}class="{{.}}"{{ end }}>
|
||||
{{ with .Get "link" }}<a href="{{ . }}">{{ end }}
|
||||
<img src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" }}{{ end }}"{{ end }} />
|
||||
<figure {{ with .Get "class" }}class="{{ . }}"{{ end }}>
|
||||
{{ with .Get "link" }}<a href="{{ . }}">{{ end }}
|
||||
<img src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" }}{{ end }}"{{ end }} />
|
||||
{{ if .Get "link" }}</a>{{ end }}
|
||||
{{ if or (or (.Get "title") (.Get "caption")) (.Get "attr") }}
|
||||
<figcaption>{{ if isset .Params "title" }}
|
||||
<figcaption>{{ if isset .Params "title" }}
|
||||
<h4>{{ .Get "title" }}</h4>{{ end }}
|
||||
{{ if or (.Get "caption") (.Get "attr") }}<p>
|
||||
{{ .Get "caption" }}
|
||||
{{ with .Get "attrlink" }}<a href="{{ . }}"> {{ end }}
|
||||
{{ .Get "attr" }}
|
||||
{{ .Get "attr" }}
|
||||
{{ if .Get "attrlink" }}</a> {{ end }}
|
||||
</p> {{ end }}
|
||||
</figcaption>
|
||||
{{ end }}
|
||||
</figcaption>
|
||||
{{ end }}
|
||||
</figure>
|
||||
<!-- image -->
|
||||
{{< /code >}}
|
||||
@@ -232,10 +232,10 @@ Would be rendered as:
|
||||
|
||||
{{< code file="img-output.html" copy="false" >}}
|
||||
<figure>
|
||||
<img src="/media/spf13.jpg" />
|
||||
<figcaption>
|
||||
<h4>Steve Francia</h4>
|
||||
</figcaption>
|
||||
<img src="/media/spf13.jpg" />
|
||||
<figcaption>
|
||||
<h4>Steve Francia</h4>
|
||||
</figcaption>
|
||||
</figure>
|
||||
{{< /code >}}
|
||||
|
||||
|
||||
@@ -30,40 +30,40 @@ This single page template makes use of Hugo [base templates], the [`.Format` fun
|
||||
<section id="main">
|
||||
<h1 id="title">{{ .Title }}</h1>
|
||||
<div>
|
||||
<article id="content">
|
||||
{{ .Content }}
|
||||
</article>
|
||||
<article id="content">
|
||||
{{ .Content }}
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
<aside id="meta">
|
||||
<div>
|
||||
<section>
|
||||
<h4 id="date"> {{ .Date.Format "Mon Jan 2, 2006" }} </h4>
|
||||
<h5 id="wordcount"> {{ .WordCount }} Words </h5>
|
||||
</section>
|
||||
{{ with .GetTerms "topics" }}
|
||||
<ul id="topics">
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{ with .GetTerms "tags" }}
|
||||
<ul id="tags">
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
</div>
|
||||
<div>
|
||||
{{ with .PrevInSection }}
|
||||
<a class="previous" href="{{.Permalink }}"> {{.Title }}</a>
|
||||
<div>
|
||||
<section>
|
||||
<h4 id="date"> {{ .Date.Format "Mon Jan 2, 2006" }} </h4>
|
||||
<h5 id="wordcount"> {{ .WordCount }} Words </h5>
|
||||
</section>
|
||||
{{ with .GetTerms "topics" }}
|
||||
<ul id="topics">
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
{{ with .NextInSection }}
|
||||
<a class="next" href="{{.Permalink }}"> {{.Title }}</a>
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{ with .GetTerms "tags" }}
|
||||
<ul id="tags">
|
||||
{{ range . }}
|
||||
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
|
||||
{{ end }}
|
||||
</div>
|
||||
</ul>
|
||||
{{ end }}
|
||||
</div>
|
||||
<div>
|
||||
{{ with .PrevInSection }}
|
||||
<a class="previous" href="{{ .Permalink }}"> {{ .Title }}</a>
|
||||
{{ end }}
|
||||
{{ with .NextInSection }}
|
||||
<a class="next" href="{{ .Permalink }}"> {{ .Title }}</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
</aside>
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
|
||||
@@ -65,10 +65,10 @@ In this example, `.Render` is passed into the template to call the [render funct
|
||||
{{< code file="layouts/_default/list.html" download="list.html" >}}
|
||||
<main id="main">
|
||||
<div>
|
||||
<h1 id="title">{{ .Title }}</h1>
|
||||
{{ range .Pages }}
|
||||
{{ .Render "summary"}}
|
||||
{{ end }}
|
||||
<h1 id="title">{{ .Title }}</h1>
|
||||
{{ range .Pages }}
|
||||
{{ .Render "summary" }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</main>
|
||||
{{< /code >}}
|
||||
|
||||
@@ -90,10 +90,10 @@ See also `.ExpiryDate`, `.Date`, `.PublishDate`, and [`.GitInfo`][gitinfo].
|
||||
: access when creating links to the content. If set, Hugo will use the `linktitle` from the front matter before `title`.
|
||||
|
||||
.Next
|
||||
: Points up to the next [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ with .Next }}{{.Permalink }}{{ end }}`. Calling `.Next` from the first page returns `nil`.
|
||||
: Points up to the next [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ with .Next }}{{ .Permalink }}{{ end }}`. Calling `.Next` from the first page returns `nil`.
|
||||
|
||||
.NextInSection
|
||||
: Points up to the next [regular page](/variables/site/#site-pages) below the same top level section (e.g. in `/blog`)). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ with .NextInSection }}{{.Permalink }}{{ end }}`. Calling `.NextInSection` from the first page returns `nil`.
|
||||
: Points up to the next [regular page](/variables/site/#site-pages) below the same top level section (e.g. in `/blog`)). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ with .NextInSection }}{{ .Permalink }}{{ end }}`. Calling `.NextInSection` from the first page returns `nil`.
|
||||
|
||||
.OutputFormats
|
||||
: contains all formats, including the current format, for a given page. Can be combined the with [`.Get` function](/functions/get/) to grab a specific format. (See [Output Formats](/templates/output-formats/).)
|
||||
@@ -112,10 +112,10 @@ See also `.ExpiryDate`, `.Date`, `.PublishDate`, and [`.GitInfo`][gitinfo].
|
||||
: the slice of strings that results from splitting .Plain into words, as defined in Go's [strings.Fields](https://pkg.go.dev/strings#Fields).
|
||||
|
||||
.Prev
|
||||
: Points down to the previous [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ if .Prev }}{{.Prev.Permalink }}{{ end }}`. Calling `.Prev` from the last page returns `nil`.
|
||||
: Points down to the previous [regular page](/variables/site/#site-pages) (sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath)). Example: `{{ if .Prev }}{{ .Prev.Permalink }}{{ end }}`. Calling `.Prev` from the last page returns `nil`.
|
||||
|
||||
.PrevInSection
|
||||
: Points down to the previous [regular page](/variables/site/#site-pages) below the same top level section (e.g. `/blog`). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ if .PrevInSection }}{{.PrevInSection.Permalink }}{{ end }}`. Calling `.PrevInSection` from the last page returns `nil`.
|
||||
: Points down to the previous [regular page](/variables/site/#site-pages) below the same top level section (e.g. `/blog`). Pages are sorted by Hugo's [default sort](/templates/lists#default-weight--date--linktitle--filepath). Example: `{{ if .PrevInSection }}{{ .PrevInSection.Permalink }}{{ end }}`. Calling `.PrevInSection` from the last page returns `nil`.
|
||||
|
||||
.PublishDate
|
||||
: the date on which the content was or will be published; `.Publishdate` pulls from the `publishdate` field in a content's front matter. See also `.ExpiryDate`, `.Date`, and `.Lastmod`.
|
||||
|
||||
@@ -18,8 +18,8 @@ Also see [List templates](/templates/lists) for an overview of sort methods.
|
||||
|
||||
`.Next` and `.Prev` on `Pages` work similar to the methods with the same names on `.Page`, but are more flexible (and slightly slower) as they can be used on any page collection.
|
||||
|
||||
`.Next` points **up** to the next page relative to the page sent in as the argument. Example: `{{ with .Site.RegularPages.Next . }}{{.RelPermalink }}{{ end }}`. Calling `.Next` with the first page in the collection returns `nil`.
|
||||
`.Next` points **up** to the next page relative to the page sent in as the argument. Example: `{{ with .Site.RegularPages.Next . }}{{ .RelPermalink }}{{ end }}`. Calling `.Next` with the first page in the collection returns `nil`.
|
||||
|
||||
## .Prev PAGE
|
||||
|
||||
`.Prev` points **down** to the previous page relative to the page sent in as the argument. Example: `{{ with .Site.RegularPages.Prev . }}{{.RelPermalink }}{{ end }}`. Calling `.Prev` with the last page in the collection returns `nil`.
|
||||
`.Prev` points **down** to the previous page relative to the page sent in as the argument. Example: `{{ with .Site.RegularPages.Prev . }}{{ .RelPermalink }}{{ end }}`. Calling `.Prev` with the last page in the collection returns `nil`.
|
||||
@@ -111,7 +111,7 @@ baseURL = "https://yoursite.example.com/"
|
||||
You can use `.Site.Params` in a [partial template](/templates/partials/) to call the default site description:
|
||||
|
||||
{{< code file="layouts/partials/head.html" >}}
|
||||
<meta name="description" content="{{ if .IsHome }}{{ $.Site.Params.description }}{{ else }}{{.Description }}{{ end }}" />
|
||||
<meta name="description" content="{{ if .IsHome }}{{ $.Site.Params.description }}{{ else }}{{ .Description }}{{ end }}" />
|
||||
{{< /code >}}
|
||||
|
||||
## The `.Site.Pages` Variable {#site-pages}
|
||||
|
||||
Reference in new issue
Block a user