Use code-toggle shortcode where appropriate

This commit is contained in:
Joe Mooring 2023-03-27 14:54:22 -07:00 committed by Joe Mooring
parent f11cabf375
commit 7785fa7d9f
10 changed files with 47 additions and 84 deletions

View File

@ -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/

View File

@ -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:

View File

@ -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

View File

@ -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]:

View File

@ -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" }}

View File

@ -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]:

View File

@ -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

View File

@ -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`.

View File

@ -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