docs: Prepare for new sub tree

See #11925
This commit is contained in:
Bjørn Erik Pedersen
2024-01-27 10:47:28 +01:00
parent 1083bf7c08
commit fc7de7136a
1157 changed files with 0 additions and 64232 deletions

View File

@@ -1,78 +0,0 @@
---
title: Alphabetical
description: Returns an ordered taxonomy, sorted alphabetically by term.
categories: []
keywords: []
action:
related:
- methods/taxonomy/ByCount
returnType: page.OrderedTaxonomy
signatures: [TAXONOMY.Alphabetical]
toc: true
---
The `Alphabetical` method on a `Taxonomy` object returns an [ordered taxonomy], sorted alphabetically by [term].
While a `Taxonomy` object is a [map], an ordered taxonomy is a [slice], where each element is an object that contains the term and a slice of its [weighted pages].
{{% include "methods/taxonomy/_common/get-a-taxonomy-object.md" %}}
## Get the ordered taxonomy
Now that we have captured the “genres” Taxonomy object, lets get the ordered taxonomy sorted alphabetically by term:
```go-html-template
{{ $taxonomyObject.Alphabetical }}
```
To reverse the sort order:
```go-html-template
{{ $taxonomyObject.Alphabetical.Reverse }}
```
To inspect the data structure:
```go-html-template
<pre>{{ jsonify (dict "indent" " ") $taxonomyObject.Alphabetical }}</pre>
```
{{% include "methods/taxonomy/_common/ordered-taxonomy-element-methods.md" %}}
## Example
With this template:
```go-html-template
{{ range $taxonomyObject.Alphabetical }}
<h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a> ({{ .Count }})</h2>
<ul>
{{ range .Pages.ByTitle }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end }}
</ul>
{{ end }}
```
Hugo renders:
```html
<h2><a href="/genres/romance/">romance</a> (2)</h2>
<ul>
<li><a href="/books/jamaica-inn/">Jamaica inn</a></li>
<li><a href="/books/pride-and-prejudice/">Pride and prejudice</a></li>
</ul>
<h2><a href="/genres/suspense/">suspense</a> (3)</h2>
<ul>
<li><a href="/books/and-then-there-were-none/">And then there were none</a></li>
<li><a href="/books/death-on-the-nile/">Death on the nile</a></li>
<li><a href="/books/jamaica-inn/">Jamaica inn</a></li>
</ul>
```
[ordered taxonomy]: /getting-started/glossary/#ordered-taxonomy
[term]: /getting-started/glossary/#term
[map]: /getting-started/glossary/#map
[slice]: /getting-started/glossary/#slice
[term]: /getting-started/glossary/#term
[weighted pages]: /getting-started/glossary/#weighted-page

View File

@@ -1,78 +0,0 @@
---
title: ByCount
description: Returns an ordered taxonomy, sorted by the number of pages associated with each term.
categories: []
keywords: []
action:
related:
- methods/taxonomy/Alphabetical
returnType: page.OrderedTaxonomy
signatures: [TAXONOMY.ByCount]
toc: true
---
The `ByCount` method on a `Taxonomy` object returns an [ordered taxonomy], sorted by the number of pages associated with each [term].
While a `Taxonomy` object is a [map], an ordered taxonomy is a [slice], where each element is an object that contains the term and a slice of its [weighted pages].
{{% include "methods/taxonomy/_common/get-a-taxonomy-object.md" %}}
## Get the ordered taxonomy
Now that we have captured the “genres” Taxonomy object, lets get the ordered taxonomy sorted by the number of pages associated with each term:
```go-html-template
{{ $taxonomyObject.ByCount }}
```
To reverse the sort order:
```go-html-template
{{ $taxonomyObject.ByCount.Reverse }}
```
To inspect the data structure:
```go-html-template
<pre>{{ jsonify (dict "indent" " ") $taxonomyObject.ByCount }}</pre>
```
{{% include "methods/taxonomy/_common/ordered-taxonomy-element-methods.md" %}}
## Example
With this template:
```go-html-template
{{ range $taxonomyObject.ByCount }}
<h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a> ({{ .Count }})</h2>
<ul>
{{ range .Pages.ByTitle }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end }}
</ul>
{{ end }}
```
Hugo renders:
```html
<h2><a href="/genres/suspense/">suspense</a> (3)</h2>
<ul>
<li><a href="/books/and-then-there-were-none/">And then there were none</a></li>
<li><a href="/books/death-on-the-nile/">Death on the nile</a></li>
<li><a href="/books/jamaica-inn/">Jamaica inn</a></li>
</ul>
<h2><a href="/genres/romance/">romance</a> (2)</h2>
<ul>
<li><a href="/books/jamaica-inn/">Jamaica inn</a></li>
<li><a href="/books/pride-and-prejudice/">Pride and prejudice</a></li>
</ul>
```
[ordered taxonomy]: /getting-started/glossary/#ordered-taxonomy
[term]: /getting-started/glossary/#term
[map]: /getting-started/glossary/#map
[slice]: /getting-started/glossary/#slice
[term]: /getting-started/glossary/#term
[weighted pages]: /getting-started/glossary/#weighted-page

View File

@@ -1,26 +0,0 @@
---
title: Count
description: Returns the number of number of weighted pages to which the given term has been assigned.
categories: []
keywords: []
action:
related: []
returnType: int
signatures: [TAXONOMY.Count TERM]
toc: true
---
The `Count` method on a `Taxonomy` object returns the number of number of [weighted pages] to which the given [term] has been assigned.
{{% include "methods/taxonomy/_common/get-a-taxonomy-object.md" %}}
## Count the weighted pages
Now that we have captured the "genres" `Taxonomy` object, let's count the number of weighted pages to which the "suspense" term has been assigned:
```go-html-template
{{ $taxonomyObject.Count "suspense" }} → 3
```
[weighted pages]: /getting-started/glossary/#weighted-page
[term]: /getting-started/glossary/#term

View File

@@ -1,72 +0,0 @@
---
title: Get
description: Returns a slice of weighted pages to which the given term has been assigned.
categories: []
keywords: []
action:
related: []
returnType: page.WeightedPages
signatures: [TAXONOMY.Get TERM]
toc: true
---
The `Get` method on a `Taxonomy` object returns a slice of [weighted pages] to which the given [term] has been assigned.
{{% include "methods/taxonomy/_common/get-a-taxonomy-object.md" %}}
## Get the weighted pages
Now that we have captured the "genres" `Taxonomy` object, let's get the weighted pages to which the "suspense" term has been assigned:
```go-html-template
{{ $weightedPages := $taxonomyObject.Get "suspense" }}
```
The above is equivalent to:
```go-html-template
{{ $weightedPages := $taxonomyObject.suspense }}
```
But, if the term is not a valid [identifier], you cannot use the [chaining] syntax. For example, this will throw an error because the identifier contains a hyphen:
```go-html-template
{{ $weightedPages := $taxonomyObject.my-genre }}
```
You could also use the [`index`] function, but the syntax is more verbose:
```go-html-template
{{ $weightedPages := index $taxonomyObject "my-genre" }}
```
To inspect the data structure:
```go-html-template
<pre>{{ jsonify (dict "indent" " ") $weightedPages }}</pre>
```
## Example
With this template:
```go-html-template
{{ $weightedPages := $taxonomyObject.Get "suspense" }}
{{ range $weightedPages }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}
```
Hugo renders:
```html
<h2><a href="/books/jamaica-inn/">Jamaica inn</a></h2>
<h2><a href="/books/death-on-the-nile/">Death on the nile</a></h2>
<h2><a href="/books/and-then-there-were-none/">And then there were none</a></h2>
```
[chaining]: /getting-started/glossary/#chain
[`index`]: /functions/collections/indexfunction
[identifier]: /getting-started/glossary/#identifier
[term]: /getting-started/glossary/#term
[weighted pages]: /getting-started/glossary/#weighted-page

View File

@@ -1,13 +0,0 @@
---
cascade:
_build:
list: never
publishResources: false
render: never
---
<!--
Files within this headless branch bundle are markdown snippets. Each file must contain front matter delimiters, though front matter fields are not required.
Include the rendered content using the "include" shortcode.
-->

View File

@@ -1,68 +0,0 @@
---
# Do not remove front matter.
---
Before we can use a `Taxonomy` method, we need to capture a `Taxonomy` object.
## Capture a taxonomy object
Consider this site configuration:
{{< code-toggle file=hugo >}}
[taxonomies]
genre = 'genres'
author = 'authors'
{{< /code-toggle >}}
And this content structure:
```text
content/
├── books/
│ ├── and-then-there-were-none.md --> genres: suspense
│ ├── death-on-the-nile.md --> genres: suspense
│ └── jamaica-inn.md --> genres: suspense, romance
│ └── pride-and-prejudice.md --> genres: romance
└── _index.md
```
To capture the "genres" taxonomy object from within any template, use the [`Taxonomies`] method on a `Site` object.
```go-html-template
{{ $taxonomyObject := .Site.Taxonomies.genres }}
```
To capture the "genres" taxonomy object when rendering its page with a taxonomy template, use the [`Terms`] method on the page's [`Data`] object:
{{< code file=layouts/_default/taxonomy.html >}}
{{ $taxonomyObject := .Data.Terms }}
{{< /code >}}
To inspect the data structure:
```go-html-template
<pre>{{ jsonify (dict "indent" " ") $taxonomyObject }}</pre>
```
Although the [`Alphabetical`] and [`ByCount`] methods provide a better data structure for ranging through the taxonomy, you can render the weighted pages by term directly from the `Taxonomy` object:
```go-html-template
{{ range $term, $weightedPages := $taxonomyObject }}
<h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a></h2>
<ul>
{{ range $weightedPages }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>
{{ end }}
```
In the example above, the first anchor element is a link to the term page.
[`Alphabetical`]: /methods/taxonomy/alphabetical
[`ByCount`]: /methods/taxonomy/bycount
[`data`]: /methods/page/data
[`terms`]: /methods/page/data/#in-a-taxonomy-template
[`taxonomies`]: /methods/site/taxonomies

View File

@@ -1,25 +0,0 @@
---
# Do not remove front matter.
---
An ordered taxonomy is a slice, where each element is an object that contains the term and a slice of its weighted pages.
Each element of the slice provides these methods:
Count
: (`int`) Returns the number of pages to which the term is assigned.
Page
: (`page.Page`) Returns the term's `Page` object, useful for linking to the term page.
Pages
: (`page.Pages`) Returns a `Pages` object containing the `Page` objects to which the term is assigned, sorted by [taxonomic weight]. To sort or group, use any of the [methods] available to the `Pages` object. For example, sort by the last modification date.
Term
: (`string`) Returns the term name.
WeightedPages
: (`page.WeightedPages`) Returns a slice of weighted pages to which the term is assigned, sorted by [taxonomic weight]. The `Pages` method above is more flexible, allowing you to sort and group.
[methods]: /methods/pages
[taxonomic weight]: /getting-started/glossary/#taxonomic-weight

View File

@@ -1,12 +0,0 @@
---
title: Taxonomy methods
linkTitle: Taxonomy
description: Use these methods with Taxonomy objects.
keywords: []
menu:
docs:
identifier:
parent: methods
---
Use these methods with Taxonomy objects.