Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'

This commit is contained in:
Bjørn Erik Pedersen
2025-04-10 13:04:51 +02:00
987 changed files with 12379 additions and 14083 deletions

View File

@@ -3,23 +3,21 @@ 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
params:
functions_and_methods:
returnType: page.OrderedTaxonomy
signatures: [TAXONOMY.Alphabetical]
---
The `Alphabetical` method on a `Taxonomy` object returns an [ordered taxonomy](g), sorted alphabetically by [term](g).
While a `Taxonomy` object is a [map](g), an ordered taxonomy is a [slice](g), where each element is an object that contains the term and a slice of its [weighted pages](g).
{{% include "methods/taxonomy/_common/get-a-taxonomy-object.md" %}}
{{% include "/_common/methods/taxonomy/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:
Now that we have captured the “genres” Taxonomy object, let's get the ordered taxonomy sorted alphabetically by term:
```go-html-template
{{ $taxonomyObject.Alphabetical }}
@@ -37,7 +35,7 @@ To inspect the data structure:
<pre>{{ debug.Dump $taxonomyObject.Alphabetical }}</pre>
```
{{% include "methods/taxonomy/_common/ordered-taxonomy-element-methods.md" %}}
{{% include "/_common/methods/taxonomy/ordered-taxonomy-element-methods.md" %}}
## Example

View File

@@ -3,23 +3,21 @@ 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
params:
functions_and_methods:
returnType: page.OrderedTaxonomy
signatures: [TAXONOMY.ByCount]
---
The `ByCount` method on a `Taxonomy` object returns an [ordered taxonomy](g), sorted by the number of pages associated with each [term](g).
While a `Taxonomy` object is a [map](g), an ordered taxonomy is a [slice](g), where each element is an object that contains the term and a slice of its [weighted pages](g).
{{% include "methods/taxonomy/_common/get-a-taxonomy-object.md" %}}
{{% include "/_common/methods/taxonomy/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:
Now that we have captured the “genres” Taxonomy object, let's get the ordered taxonomy sorted by the number of pages associated with each term:
```go-html-template
{{ $taxonomyObject.ByCount }}
@@ -37,7 +35,7 @@ To inspect the data structure:
<pre>{{ debug.Dump $taxonomyObject.ByCount }}</pre>
```
{{% include "methods/taxonomy/_common/ordered-taxonomy-element-methods.md" %}}
{{% include "/_common/methods/taxonomy/ordered-taxonomy-element-methods.md" %}}
## Example

View File

@@ -3,16 +3,15 @@ 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
params:
functions_and_methods:
returnType: int
signatures: [TAXONOMY.Count TERM]
---
The `Count` method on a `Taxonomy` object returns the number of number of [weighted pages](g) to which the given [term](g) has been assigned.
{{% include "methods/taxonomy/_common/get-a-taxonomy-object.md" %}}
{{% include "/_common/methods/taxonomy/get-a-taxonomy-object.md" %}}
## Count the weighted pages

View File

@@ -3,16 +3,15 @@ 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
params:
functions_and_methods:
returnType: page.WeightedPages
signatures: [TAXONOMY.Get TERM]
---
The `Get` method on a `Taxonomy` object returns a slice of [weighted pages](g) to which the given [term](g) has been assigned.
{{% include "methods/taxonomy/_common/get-a-taxonomy-object.md" %}}
{{% include "/_common/methods/taxonomy/get-a-taxonomy-object.md" %}}
## Get the weighted pages

View File

@@ -3,10 +3,10 @@ title: Page
description: Returns the taxonomy page or nil if the taxonomy has no terms.
categories: []
keywords: []
action:
related: []
returnType: page.Page
signatures: [TAXONOMY.Page]
params:
functions_and_methods:
returnType: page.Page
signatures: [TAXONOMY.Page]
---
{{< new-in 0.125.0 />}}

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,67 +0,0 @@
---
_comment: 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>{{ debug.Dump $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,24 +0,0 @@
---
_comment: 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](g). 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/

View File

@@ -3,11 +3,5 @@ title: Taxonomy methods
linkTitle: Taxonomy
description: Use these methods with Taxonomy objects.
keywords: []
menu:
docs:
identifier:
parent: methods
aliases: [/variables/taxonomy/]
---
Use these methods with Taxonomy objects.