mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-07 19:46:54 -04:00
Use code-toggle shortcode where appropriate
This commit is contained in:
parent
f11cabf375
commit
7785fa7d9f
@ -83,7 +83,7 @@ Hugo natively supports taxonomies.
|
||||
|
||||
Without adding a single line to your [site config][config] file, Hugo will automatically create taxonomies for `tags` and `categories`. That would be the same as manually [configuring your taxonomies](#configure-taxonomies) as below:
|
||||
|
||||
{{< code-toggle copy=false >}}
|
||||
{{< code-toggle file="config" copy=false >}}
|
||||
[taxonomies]
|
||||
tag = "tags"
|
||||
category = "categories"
|
||||
@ -91,7 +91,7 @@ Without adding a single line to your [site config][config] file, Hugo will autom
|
||||
|
||||
If you do not want Hugo to create any taxonomies, set `disableKinds` in your [site config][config] to the following:
|
||||
|
||||
{{< code-toggle copy=false >}}
|
||||
{{< code-toggle file="config" copy=false >}}
|
||||
disableKinds = ["taxonomy","term"]
|
||||
{{</ code-toggle >}}
|
||||
|
||||
@ -114,7 +114,7 @@ Custom taxonomies other than the [defaults](#default-taxonomies) must be defined
|
||||
While adding custom taxonomies, you need to put in the default taxonomies too, _if you want to keep them_.
|
||||
{{% /note %}}
|
||||
|
||||
{{< code-toggle copy=false >}}
|
||||
{{< code-toggle file="config" copy=false >}}
|
||||
[taxonomies]
|
||||
tag = "tags"
|
||||
category = "categories"
|
||||
@ -125,7 +125,7 @@ While adding custom taxonomies, you need to put in the default taxonomies too, _
|
||||
|
||||
If you want to have just the default `tags` taxonomy, and remove the `categories` taxonomy for your site, you can do so by modifying the `taxonomies` value in your [site config][config].
|
||||
|
||||
{{< code-toggle copy=false >}}
|
||||
{{< code-toggle file="config" copy=false >}}
|
||||
[taxonomies]
|
||||
tag = "tags"
|
||||
{{</ code-toggle >}}
|
||||
@ -156,7 +156,7 @@ If you would like the ability to quickly generate content files with preconfigur
|
||||
|
||||
### Example: Front Matter with Taxonomies
|
||||
|
||||
{{< code-toggle copy=false >}}
|
||||
{{< code-toggle file="content/example.md" fm=true copy=false >}}
|
||||
title = "Hugo: A fast and flexible static site generator"
|
||||
tags = [ "Development", "Go", "fast", "Blogging" ]
|
||||
categories = [ "Development" ]
|
||||
@ -191,13 +191,10 @@ Currently taxonomies only support the [default `weight => date` ordering of list
|
||||
|
||||
If you need to add custom metadata to your taxonomy terms, you will need to create a page for that term at `/content/<TAXONOMY>/<TERM>/_index.md` and add your metadata in its front matter. Continuing with our 'Actors' example, let's say you want to add a Wikipedia page link to each actor. Your terms pages would be something like this:
|
||||
|
||||
{{< code file="/content/actors/bruce-willis/_index.md" >}}
|
||||
---
|
||||
{{< code-toggle file="content/actors/bruce-willis/_index.md" fm=true copy=false >}}
|
||||
title: "Bruce Willis"
|
||||
wikipedia: "https://en.wikipedia.org/wiki/Bruce_Willis"
|
||||
---
|
||||
{{< /code >}}
|
||||
|
||||
{{< /code-toggle >}}
|
||||
|
||||
[`urlize` template function]: /functions/urlize/
|
||||
[content section]: /content-management/sections/
|
||||
|
@ -30,11 +30,10 @@ POTENTIAL NEW CONTENT: see apply/sequence discussion: https://discourse.gohugo.i
|
||||
|
||||
Here is an example of a content file with `names:` as a front matter field:
|
||||
|
||||
```
|
||||
+++
|
||||
{{< code-toggle file="content/example.md" fm=true copy=false >}}
|
||||
title: Example
|
||||
names: [ "Derek Perkins", "Joe Bergevin", "Tanner Linsley" ]
|
||||
+++
|
||||
```
|
||||
{{< /code-toggle >}}
|
||||
|
||||
You can then use `apply` as follows:
|
||||
|
||||
|
@ -25,8 +25,8 @@ display_toc = true
|
||||
|
||||
**Content**
|
||||
|
||||
{{< code-toggle file="content/about.md" fm=true copy=false >}}
|
||||
title = 'About'
|
||||
{{< code-toggle file="content/example.md" fm=true copy=false >}}
|
||||
title = 'Example'
|
||||
date = 2023-01-01
|
||||
draft = false
|
||||
display_toc = false
|
||||
|
@ -19,13 +19,11 @@ relatedfuncs: []
|
||||
|
||||
The following examples pull from a content file with the following front matter:
|
||||
|
||||
{{< code file="content/blog/greatest-city.md" copy="false" >}}
|
||||
+++
|
||||
{{< code-toggle file="content/blog/greatest-city.md" fm=true copy=false >}}
|
||||
title = "The World's Greatest City"
|
||||
location = "Chicago IL"
|
||||
tags = ["pizza","beer","hot dogs"]
|
||||
+++
|
||||
{{< /code >}}
|
||||
{{< /code-toggle >}}
|
||||
|
||||
The following might be used as a partial within a [single page template][singletemplate]:
|
||||
|
||||
|
@ -33,11 +33,10 @@ SQL][wherekeyword].
|
||||
|
||||
It can be used by dot-chaining the second argument to refer to a nested element of a value.
|
||||
|
||||
```
|
||||
+++
|
||||
{{< code-toggle file="content/example.md" fm=true copy=false >}}
|
||||
title: Example
|
||||
series: golang
|
||||
+++
|
||||
```
|
||||
{{< /code-toggle >}}
|
||||
|
||||
```go-html-template
|
||||
{{ range where .Site.Pages "Params.series" "golang" }}
|
||||
|
@ -536,16 +536,12 @@ You can provide variables to be used by templates in individual content's [front
|
||||
|
||||
An example of this is used in the Hugo docs. Most of the pages benefit from having the table of contents provided, but sometimes the table of contents doesn't make a lot of sense. We've defined a `notoc` variable in our front matter that will prevent a table of contents from rendering when specifically set to `true`.
|
||||
|
||||
Here is the example front matter (YAML):
|
||||
Here is the example front matter:
|
||||
|
||||
```yml
|
||||
---
|
||||
title: Roadmap
|
||||
lastmod: 2017-03-05
|
||||
date: 2013-11-18
|
||||
{{< code-toggle file="content/example.md" fm=true copy=false >}}
|
||||
title: Example
|
||||
notoc: true
|
||||
---
|
||||
```
|
||||
{{< /code-toggle >}}
|
||||
|
||||
Here is an example of corresponding code that could be used inside a `toc.html` [partial template][partials]:
|
||||
|
||||
|
@ -94,16 +94,16 @@ You can now access this `_index.md`'s' content in your list template:
|
||||
<main>
|
||||
<article>
|
||||
<header>
|
||||
<h1>{{.Title }}</h1>
|
||||
<h1>{{.Title}}</h1>
|
||||
</header>
|
||||
<!-- "{{.Content }}" pulls from the markdown content of the corresponding _index.md -->
|
||||
{{.Content }}
|
||||
<!-- "{{.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>
|
||||
<a href="{{.Permalink}}">{{.Date.Format "2006-01-02"}} | {{.Title}}</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
@ -133,7 +133,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:
|
||||
|
||||
@ -381,14 +381,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>
|
||||
@ -544,7 +544,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:
|
||||
|
||||
|
@ -168,17 +168,15 @@ Note that in the above examples, the _output formats_ for `section`,
|
||||
* These names are case insensitive.
|
||||
* These can be overridden per `Page` in the front matter of content files.
|
||||
|
||||
The following is an example of `YAML` front matter in a content file that defines output formats for the rendered `Page`:
|
||||
The following is an example of front matter in a content file that defines output formats for the rendered `Page`:
|
||||
|
||||
```yaml
|
||||
---
|
||||
date: "2016-03-19"
|
||||
{{< code-toggle file="content/example.md" fm=true copy=false >}}
|
||||
title: Example
|
||||
outputs:
|
||||
- html
|
||||
- amp
|
||||
- json
|
||||
---
|
||||
```
|
||||
{{< /code-toggle >}}
|
||||
|
||||
## List Output formats
|
||||
|
||||
|
@ -150,16 +150,14 @@ Weights of zero are thus treated specially: if two pages have unequal weights, a
|
||||
|
||||
Content can be assigned weight for each taxonomy that it's assigned to.
|
||||
|
||||
```txt
|
||||
+++
|
||||
|
||||
{{< code-toggle file="content/example.md" fm=true copy=false >}}
|
||||
tags = [ "a", "b", "c" ]
|
||||
tags_weight = 22
|
||||
categories = ["d"]
|
||||
title = "foo"
|
||||
title = "Example"
|
||||
categories_weight = 44
|
||||
+++
|
||||
Front Matter with weighted tags and categories
|
||||
```
|
||||
{{< /code-toggle >}}
|
||||
|
||||
The convention is `taxonomyname_weight`.
|
||||
|
||||
|
@ -260,13 +260,11 @@ There are one caveat with this, and this isn't new, but it's worth mentioning he
|
||||
|
||||
Any other value defined in the front matter in a content file, including taxonomies, will be made available as part of the `.Params` variable.
|
||||
|
||||
```yml
|
||||
---
|
||||
title: My First Post
|
||||
date: 2017-02-20T15:26:23-06:00
|
||||
{{< code-toggle file="content/example.md" fm=true copy=false >}}
|
||||
title: Example
|
||||
categories: [one]
|
||||
tags: [two,three,four]
|
||||
```
|
||||
{{< /code-toggle >}}
|
||||
|
||||
With the above front matter, the `tags` and `categories` taxonomies are accessible via the following:
|
||||
|
||||
@ -279,14 +277,11 @@ Page-level `.Params` are *only* accessible in lowercase.
|
||||
|
||||
The `.Params` variable is particularly useful for the introduction of user-defined front matter fields in content files. For example, a Hugo website on book reviews could have the following front matter in `/content/review/book01.md`:
|
||||
|
||||
```yml
|
||||
---
|
||||
...
|
||||
{{< code-toggle file="content/example.md" fm=true copy=false >}}
|
||||
title: Example
|
||||
affiliatelink: "http://www.my-book-link.here"
|
||||
recommendedby: "My Mother"
|
||||
...
|
||||
---
|
||||
```
|
||||
{{< /code-toggle >}}
|
||||
|
||||
These fields would then be accessible to the `/themes/yourtheme/layouts/review/single.html` template through `.Params.affiliatelink` and `.Params.recommendedby`, respectively.
|
||||
|
||||
@ -322,37 +317,20 @@ The `.Param` method provides a way to resolve a single value according to it's d
|
||||
|
||||
When front matter contains nested fields like the following:
|
||||
|
||||
```yml
|
||||
---
|
||||
{{< code-toggle file="content/example.md" fm=true copy=false >}}
|
||||
title: Example
|
||||
author:
|
||||
given_name: John
|
||||
family_name: Feminella
|
||||
display_name: John Feminella
|
||||
---
|
||||
```
|
||||
{{< /code-toggle >}}
|
||||
|
||||
`.Param` can access these fields by concatenating the field names together with a dot:
|
||||
|
||||
```go-html-template
|
||||
{{ $.Param "author.display_name" }}
|
||||
```
|
||||
|
||||
If your front matter contains a top-level key that is ambiguous with a nested key, as in the following case:
|
||||
|
||||
```yml
|
||||
---
|
||||
favorites.flavor: vanilla
|
||||
favorites:
|
||||
flavor: chocolate
|
||||
---
|
||||
```
|
||||
|
||||
The top-level key will be preferred. Therefore, the following method, when applied to the previous example, will print `vanilla` and not `chocolate`:
|
||||
|
||||
```txt
|
||||
{{ $.Param "favorites.flavor" }}
|
||||
=> vanilla
|
||||
```
|
||||
|
||||
[gitinfo]: /variables/git/
|
||||
[File Variables]: /variables/files/
|
||||
[bundle]: /content-management/page-bundles
|
||||
|
Loading…
x
Reference in New Issue
Block a user