From 7785fa7d9fbea553dbf520eef86bdeaaf215e1fe Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Mon, 27 Mar 2023 14:54:22 -0700 Subject: [PATCH] Use code-toggle shortcode where appropriate --- content/en/content-management/taxonomies.md | 17 ++++----- content/en/functions/apply.md | 7 ++-- content/en/functions/param.md | 4 +- content/en/functions/urlize.md | 6 +-- content/en/functions/where.md | 7 ++-- content/en/templates/introduction.md | 12 ++---- content/en/templates/lists/index.md | 16 ++++---- content/en/templates/output-formats.md | 10 ++--- content/en/templates/taxonomy-templates.md | 10 ++--- content/en/variables/page.md | 42 +++++---------------- 10 files changed, 47 insertions(+), 84 deletions(-) diff --git a/content/en/content-management/taxonomies.md b/content/en/content-management/taxonomies.md index 8c3ef53e5..6d4655228 100644 --- a/content/en/content-management/taxonomies.md +++ b/content/en/content-management/taxonomies.md @@ -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"] {{}} @@ -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" {{}} @@ -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///_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/ diff --git a/content/en/functions/apply.md b/content/en/functions/apply.md index 983e2fdb9..4c36cf17e 100644 --- a/content/en/functions/apply.md +++ b/content/en/functions/apply.md @@ -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: diff --git a/content/en/functions/param.md b/content/en/functions/param.md index 4f1764814..96cdfe73b 100644 --- a/content/en/functions/param.md +++ b/content/en/functions/param.md @@ -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 diff --git a/content/en/functions/urlize.md b/content/en/functions/urlize.md index 1ba20506b..ad5a79ee5 100644 --- a/content/en/functions/urlize.md +++ b/content/en/functions/urlize.md @@ -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]: diff --git a/content/en/functions/where.md b/content/en/functions/where.md index 07bf913f5..67888fae7 100644 --- a/content/en/functions/where.md +++ b/content/en/functions/where.md @@ -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" }} diff --git a/content/en/templates/introduction.md b/content/en/templates/introduction.md index 2f907e033..682a9cce0 100644 --- a/content/en/templates/introduction.md +++ b/content/en/templates/introduction.md @@ -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]: diff --git a/content/en/templates/lists/index.md b/content/en/templates/lists/index.md index 95d45a9d9..c78555d39 100644 --- a/content/en/templates/lists/index.md +++ b/content/en/templates/lists/index.md @@ -94,16 +94,16 @@ You can now access this `_index.md`'s' content in your list template:
-

{{.Title }}

+

{{.Title}}

- - {{.Content }} + + {{.Content}}
@@ -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" >}} {{ range .Pages.GroupBy "Section" }} {{ with $.Site.GetPage "section" .Key }} -

{{.Title }}

+

{{.Title}}

{{ else }}

{{ .Key | title }}

@@ -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: diff --git a/content/en/templates/output-formats.md b/content/en/templates/output-formats.md index 1aec917eb..1df840578 100644 --- a/content/en/templates/output-formats.md +++ b/content/en/templates/output-formats.md @@ -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 diff --git a/content/en/templates/taxonomy-templates.md b/content/en/templates/taxonomy-templates.md index 4411164da..0cf7ea729 100644 --- a/content/en/templates/taxonomy-templates.md +++ b/content/en/templates/taxonomy-templates.md @@ -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`. diff --git a/content/en/variables/page.md b/content/en/variables/page.md index c6d29d39c..6704075f4 100644 --- a/content/en/variables/page.md +++ b/content/en/variables/page.md @@ -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