aboutsummaryrefslogtreecommitdiffhomepage
path: root/content/en/methods
diff options
context:
space:
mode:
Diffstat (limited to 'content/en/methods')
-rw-r--r--content/en/methods/_common/_index.md13
-rw-r--r--content/en/methods/_common/next-prev-on-page-vs-next-prev-on-pages.md37
-rw-r--r--content/en/methods/page/Next.md40
-rw-r--r--content/en/methods/page/NextInSection.md60
-rw-r--r--content/en/methods/page/Prev.md44
-rw-r--r--content/en/methods/page/PrevInSection.md61
-rw-r--r--content/en/methods/page/_common/next-and-prev.md60
-rw-r--r--content/en/methods/page/_common/nextinsection-and-previnsection.md78
-rw-r--r--content/en/methods/pages/Next.md44
-rw-r--r--content/en/methods/pages/Prev.md44
-rw-r--r--content/en/methods/pages/_common/next-and-prev.md72
11 files changed, 226 insertions, 327 deletions
diff --git a/content/en/methods/_common/_index.md b/content/en/methods/_common/_index.md
deleted file mode 100644
index 4328d4d14..000000000
--- a/content/en/methods/_common/_index.md
+++ /dev/null
@@ -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.
--->
diff --git a/content/en/methods/_common/next-prev-on-page-vs-next-prev-on-pages.md b/content/en/methods/_common/next-prev-on-page-vs-next-prev-on-pages.md
deleted file mode 100644
index f65037878..000000000
--- a/content/en/methods/_common/next-prev-on-page-vs-next-prev-on-pages.md
+++ /dev/null
@@ -1,37 +0,0 @@
----
-# Do not remove front matter.
----
-
-The `Next` and `Prev` methods on a `Pages` object are more flexible than the `Next` and `Prev` methods on a `Page` object.
-
-||Page collection|Custom sort order
-:--|:--|:-:
-[`PAGES.Next`] and [`PAGES.Prev`]|locally defined|✔️
-[`PAGE.Next`] and [`PAGE.Prev`]|globally defined|❌
-
-[`PAGES.Next`]: /methods/pages/next/
-[`PAGES.Prev`]: /methods/pages/prev/
-[`PAGE.Next`]: /methods/page/next/
-[`PAGE.Prev`]: /methods/page/prev/
-
-locally defined
-: Build the page collection every time you call `PAGES.Next` and `PAGES.Prev`. Navigation between pages is relative to the current page's position within the local collection, independent of the global collection.
-
-With a local collection, the navigation sort order is the same as the collection sort order.
-
-globally defined
-: Build the page collection once, on a list page. Navigation between pages is relative to the current page's position within the global collection.
-
-With a global collection, the navigation sort order is fixed, using Hugo's default sort order. In order of precedence:
-
-1. Page [weight]
-2. Page [date] (descending)
-3. Page [linkTitle], falling back to page [title]
-4. Page file path if the page is backed by a file
-
-For example, with a global collection sorted by title, the navigation sort order will use Hugo's default sort order. This is probably not what you want or expect. For this reason, the `Next` and `Prev` methods on a `Pages` object are generally a better choice.
-
-[date]: /methods/page/date/
-[weight]: /methods/page/weight/
-[linkTitle]: /methods/page/linktitle/
-[title]: /methods/page/title/
diff --git a/content/en/methods/page/Next.md b/content/en/methods/page/Next.md
index 57fc1f2f8..ff0525700 100644
--- a/content/en/methods/page/Next.md
+++ b/content/en/methods/page/Next.md
@@ -1,6 +1,6 @@
---
title: Next
-description: Returns the next page in a global page collection, relative to the given page.
+description: Returns the next page in a site's collection of regular pages, relative to the current page.
categories: []
keywords: []
action:
@@ -12,42 +12,6 @@ action:
- methods/pages/Prev
returnType: page.Page
signatures: [PAGE.Next]
-toc: true
---
-The behavior of the `Prev` and `Next` methods on a `Page` object is probably the reverse of what you expect.
-
-With this content structure:
-
-```text
-content/
-├── pages/
-│ ├── _index.md
-│ ├── page-1.md <-- front matter: weight = 10
-│ ├── page-2.md <-- front matter: weight = 20
-│ └── page-3.md <-- front matter: weight = 30
-└── _index.md
-```
-
-When you visit page-2:
-
-- The `Prev` method points to page-3
-- The `Next` method points to page-1
-
-{{% note %}}
-Use the opposite label in your navigation links as shown in the example below.
-{{% /note %}}
-
-```go-html-template
-{{ with .Next }}
- <a href="{{ .RelPermalink }}">Prev</a>
-{{ end }}
-
-{{ with .Prev }}
- <a href="{{ .RelPermalink }}">Next</a>
-{{ end }}
-```
-
-## Compare to Pages methods
-
-{{% include "methods/_common/next-prev-on-page-vs-next-prev-on-pages.md" %}}
+{{% include "methods/page/_common/next-and-prev.md" %}}
diff --git a/content/en/methods/page/NextInSection.md b/content/en/methods/page/NextInSection.md
index 59a35d03d..640e9b44a 100644
--- a/content/en/methods/page/NextInSection.md
+++ b/content/en/methods/page/NextInSection.md
@@ -1,71 +1,15 @@
---
title: NextInSection
-description: Returns the next page within a section, relative to the given page.
+description: Returns the next regular page in a section, relative to the given page.
categories: []
keywords: []
action:
related:
- methods/page/PrevInSection
- - methods/page/Next
- - methods/page/Prev
- methods/pages/Next
- methods/pages/Prev
returnType: page.Page
signatures: [PAGE.NextInSection]
---
-The behavior of the `PrevInSection` and `NextInSection` methods on a `Page` object is probably the reverse of what you expect.
-
-With this content structure:
-
-```text
-content/
-├── books/
-│ ├── _index.md
-│ ├── book-1.md
-│ ├── book-2.md
-│ └── book-3.md
-├── films/
-│ ├── _index.md
-│ ├── film-1.md
-│ ├── film-2.md
-│ └── film-3.md
-└── _index.md
-```
-
-When you visit book-2:
-
-- The `PrevInSection` method points to book-3
-- The `NextInSection` method points to book-1
-
-{{% note %}}
-Use the opposite label in your navigation links as shown in the example below.
-{{% /note %}}
-
-```go-html-template
-{{ with .NextInSection }}
- <a href="{{ .RelPermalink }}">Previous in section</a>
-{{ end }}
-
-{{ with .PrevInSection }}
- <a href="{{ .RelPermalink }}">Next in section</a>
-{{ end }}
-```
-
-{{% note %}}
-The navigation sort order may be different than the page collection sort order.
-{{% /note %}}
-
-With the `PrevInSection` and `NextInSection` methods, the navigation sort order is fixed, using Hugo’s default sort order. In order of precedence:
-
-1. Page [weight]
-2. Page [date] (descending)
-3. Page [linkTitle], falling back to page [title]
-4. Page file path if the page is backed by a file
-
-For example, with a page collection sorted by title, the navigation sort order will use Hugo’s default sort order. This is probably not what you want or expect. For this reason, the Next and Prev methods on a Pages object are generally a better choice.
-
-[date]: /methods/page/date/
-[weight]: /methods/page/weight/
-[linkTitle]: /methods/page/linktitle/
-[title]: /methods/page/title/
+{{% include "methods/page/_common/nextinsection-and-previnsection.md" %}}
diff --git a/content/en/methods/page/Prev.md b/content/en/methods/page/Prev.md
index b1a503af5..d28b50265 100644
--- a/content/en/methods/page/Prev.md
+++ b/content/en/methods/page/Prev.md
@@ -1,53 +1,17 @@
---
title: Prev
-description: Returns the previous page in a global page collection, relative to the given page.
+description: Returns the previous page in a site's collection of regular pages, relative to the current page.
categories: []
keywords: []
action:
related:
- methods/page/Next
- - methods/page/PrevInSection
- methods/page/NextInSection
- - methods/pages/Prev
+ - methods/page/PrevInSection
- methods/pages/Next
+ - methods/pages/Prev
returnType: page.Page
signatures: [PAGE.Prev]
-toc: true
---
-The behavior of the `Prev` and `Next` methods on a `Page` object is probably the reverse of what you expect.
-
-With this content structure:
-
-```text
-content/
-├── pages/
-│ ├── _index.md
-│ ├── page-1.md <-- front matter: weight = 10
-│ ├── page-2.md <-- front matter: weight = 20
-│ └── page-3.md <-- front matter: weight = 30
-└── _index.md
-```
-
-When you visit page-2:
-
-- The `Prev` method points to page-3
-- The `Next` method points to page-1
-
-{{% note %}}
-Use the opposite label in your navigation links as shown in the example below.
-{{% /note %}}
-
-```go-html-template
-{{ with .Next }}
- <a href="{{ .RelPermalink }}">Prev</a>
-{{ end }}
-
-{{ with .Prev }}
- <a href="{{ .RelPermalink }}">Next</a>
-{{ end }}
-```
-
-## Compare to Pages methods
-
-{{% include "methods/_common/next-prev-on-page-vs-next-prev-on-pages.md" %}}
+{{% include "methods/page/_common/next-and-prev.md" %}}
diff --git a/content/en/methods/page/PrevInSection.md b/content/en/methods/page/PrevInSection.md
index e6daf66c4..aaafb367e 100644
--- a/content/en/methods/page/PrevInSection.md
+++ b/content/en/methods/page/PrevInSection.md
@@ -1,72 +1,15 @@
---
title: PrevInSection
-description: Returns the previous page within a section, relative to the given page.
+description: Returns the previous regular page in a section, relative to the given page.
categories: []
keywords: []
action:
related:
- methods/page/NextInSection
- - methods/page/Next
- methods/pages/Next
- - methods/page/Prev
- methods/pages/Prev
returnType: page.Page
signatures: [PAGE.PrevInSection]
---
-
-The behavior of the `PrevInSection` and `NextInSection` methods on a `Page` object is probably the reverse of what you expect.
-
-With this content structure:
-
-```text
-content/
-├── books/
-│ ├── _index.md
-│ ├── book-1.md
-│ ├── book-2.md
-│ └── book-3.md
-├── films/
-│ ├── _index.md
-│ ├── film-1.md
-│ ├── film-2.md
-│ └── film-3.md
-└── _index.md
-```
-
-When you visit book-2:
-
-- The `PrevInSection` method points to book-3
-- The `NextInSection` method points to book-1
-
-{{% note %}}
-Use the opposite label in your navigation links as shown in the example below.
-{{% /note %}}
-
-```go-html-template
-{{ with .NextInSection }}
- <a href="{{ .RelPermalink }}">Previous in section</a>
-{{ end }}
-
-{{ with .PrevInSection }}
- <a href="{{ .RelPermalink }}">Next in section</a>
-{{ end }}
-```
-
-{{% note %}}
-The navigation sort order may be different than the page collection sort order.
-{{% /note %}}
-
-With the `PrevInSection` and `NextInSection` methods, the navigation sort order is fixed, using Hugo’s default sort order. In order of precedence:
-
-1. Page [weight]
-2. Page [date] (descending)
-3. Page [linkTitle], falling back to page [title]
-4. Page file path if the page is backed by a file
-
-For example, with a page collection sorted by title, the navigation sort order will use Hugo’s default sort order. This is probably not what you want or expect. For this reason, the Next and Prev methods on a Pages object are generally a better choice.
-
-[date]: /methods/page/date/
-[weight]: /methods/page/weight/
-[linkTitle]: /methods/page/linktitle/
-[title]: /methods/page/title/
+{{% include "methods/page/_common/nextinsection-and-previnsection.md" %}}
diff --git a/content/en/methods/page/_common/next-and-prev.md b/content/en/methods/page/_common/next-and-prev.md
new file mode 100644
index 000000000..0d1436e11
--- /dev/null
+++ b/content/en/methods/page/_common/next-and-prev.md
@@ -0,0 +1,60 @@
+---
+# Do not remove front matter.
+---
+
+Hugo determines the _next_ and _previous_ page by sorting the site's collection of regular pages according to this sorting hierarchy:
+
+Field|Precedence|Sort direction
+:--|:--|:--
+[`weight`]|1|descending
+[`date`]|2|descending
+[`linkTitle`]|3|descending
+[`path`]|4|descending
+
+[`date`]: /methods/page/date/
+[`weight`]: /methods/page/weight/
+[`linkTitle`]: /methods/page/linktitle/
+[`path`]: /methods/page/path/
+
+The sorted page collection used to determine the _next_ and _previous_ page is independent of other page collections, which may lead to unexpected behavior.
+
+For example, with this content structure:
+
+```text
+content/
+├── pages/
+│ ├── _index.md
+│ ├── page-1.md <-- front matter: weight = 10
+│ ├── page-2.md <-- front matter: weight = 20
+│ └── page-3.md <-- front matter: weight = 30
+└── _index.md
+```
+
+And these templates:
+
+{{< code file=layouts/_default/list.html >}}
+{{ range .Pages.ByWeight }}
+ <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
+{{ end }}
+{{< /code >}}
+
+{{< code file=layouts/_default/single.html >}}
+{{ with .Prev }}
+ <a href="{{ .RelPermalink }}">Previous</a>
+{{ end }}
+
+{{ with .Next }}
+ <a href="{{ .RelPermalink }}">Next</a>
+{{ end }}
+{{< /code >}}
+
+When you visit page-2:
+
+- The `Prev` method points to page-3
+- The `Next` method points to page-1
+
+To reverse the meaning of _next_ and _previous_ you can change the sort direction in your [site configuration], or use the [`Next`] and [`Prev`] methods on a `Pages` object for more flexibility.
+
+[site configuration]: getting-started/configuration/#configure-page
+[`Next`]: /methods/pages/prev
+[`Prev`]: /methods/pages/prev
diff --git a/content/en/methods/page/_common/nextinsection-and-previnsection.md b/content/en/methods/page/_common/nextinsection-and-previnsection.md
new file mode 100644
index 000000000..6c558b69e
--- /dev/null
+++ b/content/en/methods/page/_common/nextinsection-and-previnsection.md
@@ -0,0 +1,78 @@
+---
+# Do not remove front matter.
+---
+
+Hugo determines the _next_ and _previous_ page by sorting the current section's regular pages according to this sorting hierarchy:
+
+Field|Precedence|Sort direction
+:--|:--|:--
+[`weight`]|1|descending
+[`date`]|2|descending
+[`linkTitle`]|3|descending
+[`path`]|4|descending
+
+[`date`]: /methods/page/date/
+[`weight`]: /methods/page/weight/
+[`linkTitle`]: /methods/page/linktitle/
+[`path`]: /methods/page/path/
+
+The sorted page collection used to determine the _next_ and _previous_ page is independent of other page collections, which may lead to unexpected behavior.
+
+For example, with this content structure:
+
+```text
+content/
+├── pages/
+│ ├── _index.md
+│ ├── page-1.md <-- front matter: weight = 10
+│ ├── page-2.md <-- front matter: weight = 20
+│ └── page-3.md <-- front matter: weight = 30
+└── _index.md
+```
+
+And these templates:
+
+{{< code file=layouts/_default/list.html >}}
+{{ range .Pages.ByWeight }}
+ <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
+{{ end }}
+{{< /code >}}
+
+{{< code file=layouts/_default/single.html >}}
+{{ with .PrevInSection }}
+ <a href="{{ .RelPermalink }}">Previous</a>
+{{ end }}
+
+{{ with .NextInSection }}
+ <a href="{{ .RelPermalink }}">Next</a>
+{{ end }}
+{{< /code >}}
+
+When you visit page-2:
+
+- The `PrevInSection` method points to page-3
+- The `NextInSection` method points to page-1
+
+To reverse the meaning of _next_ and _previous_ you can change the sort direction in your [site configuration], or use the [`Next`] and [`Prev`] methods on a `Pages` object for more flexibility.
+
+[site configuration]: getting-started/configuration/#configure-page
+[`Next`]: /methods/pages/prev
+[`Prev`]: /methods/pages/prev
+
+## Example
+
+Code defensively by checking for page existence:
+
+```go-html-template
+{{ with .PrevInSection }}
+ <a href="{{ .RelPermalink }}">Previous</a>
+{{ end }}
+
+{{ with .NextInSection }}
+ <a href="{{ .RelPermalink }}">Next</a>
+{{ end }}
+```
+
+## Alternative
+
+Use the [`Next`] and [`Prev`] methods on a `Pages` object for more flexibility.
diff --git a/content/en/methods/pages/Next.md b/content/en/methods/pages/Next.md
index b7284609f..dcf1231ac 100644
--- a/content/en/methods/pages/Next.md
+++ b/content/en/methods/pages/Next.md
@@ -1,55 +1,17 @@
---
title: Next
-description: Returns the next page in a local page collection, relative to the given page.
+description: Returns the next page in a page collection, relative to the given page.
categories: []
keywords: []
action:
related:
- methods/pages/Prev
- methods/page/Next
- - methods/page/NextInSection
- methods/page/Prev
+ - methods/page/NextInSection
- methods/page/PrevInSection
returnType: page.Page
signatures: [PAGES.Next PAGE]
-toc: true
---
-The behavior of the `Prev` and `Next` methods on a `Pages` objects is probably the reverse of what you expect.
-
-With this content structure and the page collection sorted by weight in ascending order:
-
-```text
-content/
-├── pages/
-│ ├── _index.md
-│ ├── page-1.md <-- front matter: weight = 10
-│ ├── page-2.md <-- front matter: weight = 20
-│ └── page-3.md <-- front matter: weight = 30
-└── _index.md
-```
-
-When you visit page-2:
-
-- The `Prev` method points to page-3
-- The `Next` method points to page-1
-
-{{% note %}}
-Use the opposite label in your navigation links as shown in the example below.
-{{% /note %}}
-
-```go-html-template
-{{ $pages := where .Site.RegularPages.ByWeight "Section" "pages" }}
-
-{{ with $pages.Next . }}
- <a href="{{ .RelPermalink }}">Previous</a>
-{{ end }}
-
-{{ with $pages.Prev . }}
- <a href="{{ .RelPermalink }}">Next</a>
-{{ end }}
-```
-
-## Compare to Page methods
-
-{{% include "methods/_common/next-prev-on-page-vs-next-prev-on-pages.md" %}}
+{{% include "methods/pages/_common/next-and-prev.md" %}}
diff --git a/content/en/methods/pages/Prev.md b/content/en/methods/pages/Prev.md
index b9ef27a45..2d8738521 100644
--- a/content/en/methods/pages/Prev.md
+++ b/content/en/methods/pages/Prev.md
@@ -1,55 +1,17 @@
---
title: Prev
-description: Returns the previous page in a local page collection, relative to the given page.
+description: Returns the previous page in a page collection, relative to the given page.
categories: []
keywords: []
action:
related:
- methods/pages/Next
- methods/page/Next
- - methods/page/NextInSection
- methods/page/Prev
+ - methods/page/NextInSection
- methods/page/PrevInSection
returnType: page.Pages
signatures: [PAGES.Prev PAGE]
-toc: true
---
-The behavior of the `Prev` and `Next` methods on a `Pages` objects is probably the reverse of what you expect.
-
-With this content structure and the page collection sorted by weight in ascending order:
-
-```text
-content/
-├── pages/
-│ ├── _index.md
-│ ├── page-1.md <-- front matter: weight = 10
-│ ├── page-2.md <-- front matter: weight = 20
-│ └── page-3.md <-- front matter: weight = 30
-└── _index.md
-```
-
-When you visit page-2:
-
-- The `Prev` method points to page-3
-- The `Next` method points to page-1
-
-{{% note %}}
-Use the opposite label in your navigation links as shown in the example below.
-{{% /note %}}
-
-```go-html-template
-{{ $pages := where .Site.RegularPages.ByWeight "Section" "pages" }}
-
-{{ with $pages.Next . }}
- <a href="{{ .RelPermalink }}">Previous</a>
-{{ end }}
-
-{{ with $pages.Prev . }}
- <a href="{{ .RelPermalink }}">Next</a>
-{{ end }}
-```
-
-## Compare to Page methods
-
-{{% include "methods/_common/next-prev-on-page-vs-next-prev-on-pages.md" %}}
+{{% include "methods/pages/_common/next-and-prev.md" %}}
diff --git a/content/en/methods/pages/_common/next-and-prev.md b/content/en/methods/pages/_common/next-and-prev.md
new file mode 100644
index 000000000..e0d05de84
--- /dev/null
+++ b/content/en/methods/pages/_common/next-and-prev.md
@@ -0,0 +1,72 @@
+---
+# Do not remove front matter.
+---
+
+Hugo determines the _next_ and _previous_ page by sorting the page collection according to this sorting hierarchy:
+
+Field|Precedence|Sort direction
+:--|:--|:--
+[`weight`]|1|descending
+[`date`]|2|descending
+[`linkTitle`]|3|descending
+[`path`]|4|descending
+
+[`date`]: /methods/page/date/
+[`weight`]: /methods/page/weight/
+[`linkTitle`]: /methods/page/linktitle/
+[`path`]: /methods/page/path/
+
+The sorted page collection used to determine the _next_ and _previous_ page is independent of other page collections, which may lead to unexpected behavior.
+
+For example, with this content structure:
+
+```text
+content/
+├── pages/
+│ ├── _index.md
+│ ├── page-1.md <-- front matter: weight = 10
+│ ├── page-2.md <-- front matter: weight = 20
+│ └── page-3.md <-- front matter: weight = 30
+└── _index.md
+```
+
+And these templates:
+
+{{< code file=layouts/_default/list.html >}}
+{{ range .Pages.ByWeight}}
+ <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
+{{ end }}
+{{< /code >}}
+
+{{< code file=layouts/_default/single.html >}}
+{{ $pages := .CurrentSection.Pages.ByWeight }}
+
+{{ with $pages.Prev . }}
+ <a href="{{ .RelPermalink }}">Previous</a>
+{{ end }}
+
+{{ with $pages.Next . }}
+ <a href="{{ .RelPermalink }}">Next</a>
+{{ end }}
+{{< /code >}}
+
+When you visit page-2:
+
+- The `Prev` method points to page-3
+- The `Next` method points to page-1
+
+To reverse the meaning of _next_ and _previous_ you can chain the [`Reverse`] method to the page collection definition:
+
+{{< code file=layouts/_default/single.html >}}
+{{ $pages := .CurrentSection.Pages.ByWeight.Reverse }}
+
+{{ with $pages.Prev . }}
+ <a href="{{ .RelPermalink }}">Previous</a>
+{{ end }}
+
+{{ with $pages.Next . }}
+ <a href="{{ .RelPermalink }}">Next</a>
+{{ end }}
+{{< /code >}}
+
+[`Reverse`]: /methods/pages/reverse/