From 69b7d4c23761a45dc2b9ea75c6c9c904a885ba5d Mon Sep 17 00:00:00 2001 From: HiDeoo Date: Tue, 11 Jul 2023 12:25:51 +0200 Subject: Add pagination configuration (#303) Co-authored-by: Chris Swithinbank --- .changeset/green-jars-march.md | 5 +++ docs/src/content/docs/reference/configuration.md | 9 ++++ docs/src/content/docs/reference/frontmatter.md | 42 ++++++++++++++++++ packages/starlight/components/Footer.astro | 5 ++- packages/starlight/schema.ts | 12 ++++++ packages/starlight/schemas/prevNextLink.ts | 20 +++++++++ packages/starlight/utils/navigation.ts | 55 ++++++++++++++++++++++-- packages/starlight/utils/user-config.ts | 8 ++++ 8 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 .changeset/green-jars-march.md create mode 100644 packages/starlight/schemas/prevNextLink.ts diff --git a/.changeset/green-jars-march.md b/.changeset/green-jars-march.md new file mode 100644 index 00000000..eb6d1171 --- /dev/null +++ b/.changeset/green-jars-march.md @@ -0,0 +1,5 @@ +--- +"@astrojs/starlight": minor +--- + +Add new global `pagination` option defaulting to `true` to define whether or not the previous and next page links are shown in the footer. A page can override this setting or the link text and/or URL using the new `prev` and `next` frontmatter fields. diff --git a/docs/src/content/docs/reference/configuration.md b/docs/src/content/docs/reference/configuration.md index 3ea91414..275d9eb8 100644 --- a/docs/src/content/docs/reference/configuration.md +++ b/docs/src/content/docs/reference/configuration.md @@ -367,3 +367,12 @@ interface HeadConfig { Control whether the footer shows when the page was last updated. By default, this feature relies on your repository’s Git history and may not be accurate on some deployment platforms performing [shallow clones](https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---depthltdepthgt). A page can override this setting or the Git-based date using the [`lastUpdated` frontmatter field](/reference/frontmatter/#lastupdated). + +### `pagination` + +**type:** `boolean` +**default:** `true` + +Define if the footer should include previous and next page links. + +A page can override this setting or the link text and/or URL using the [`prev`](/reference/frontmatter/#prev) and [`next`](/reference/frontmatter/#next) frontmatter fields. diff --git a/docs/src/content/docs/reference/frontmatter.md b/docs/src/content/docs/reference/frontmatter.md index 14dded59..ede73997 100644 --- a/docs/src/content/docs/reference/frontmatter.md +++ b/docs/src/content/docs/reference/frontmatter.md @@ -146,3 +146,45 @@ title: Page with a custom last update date lastUpdated: 2022-08-09 --- ``` + +### `prev` + +**type:** `boolean | string | { link?: string; label?: string }` + +Overrides the [global `pagination` option](/reference/configuration/#pagination). If a string is specified, the generated link text will be replaced and if an object is specified, both the link and the text will can be overridden. + +```md +--- +# Hide the previous page link +prev: false +--- +``` + +```md +--- +# Override the previous page link text +prev: Continue the tutorial +--- +``` + +```md +--- +# Override both the previous page link and text +prev: + link: /unrelated-page/ + label: Check out this other page +--- +``` + +### `next` + +**type:** `boolean | string | { link?: string; label?: string }` + +Same as [`prev`](#prev) but for the next page link. + +```md +--- +# Hide the next page link +next: false +--- +``` \ No newline at end of file diff --git a/packages/starlight/components/Footer.astro b/packages/starlight/components/Footer.astro index d5925c1f..d040bb68 100644 --- a/packages/starlight/components/Footer.astro +++ b/packages/starlight/components/Footer.astro @@ -14,7 +14,10 @@ interface Props extends LocaleData { } const { entry, dir, lang, locale, sidebar } = Astro.props; -const prevNextLinks = getPrevNextLinks(sidebar); +const prevNextLinks = getPrevNextLinks(sidebar, config.pagination, { + prev: entry.data.prev, + next: entry.data.next +}); ---