From 7c0b8cb334c501678f7ab87cce372cddfdde34ed Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Wed, 29 Nov 2023 20:31:39 +0100 Subject: Add a `pagefind` boolean flag to user config (#1144) Co-authored-by: Sarah Rainsberger --- .changeset/beige-shoes-whisper.md | 5 +++++ docs/src/content/docs/reference/configuration.mdx | 10 ++++++++++ docs/src/content/docs/reference/overrides.md | 4 ++++ packages/starlight/components/Header.astro | 9 ++++++++- packages/starlight/index.ts | 1 + packages/starlight/utils/user-config.ts | 7 +++++++ 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .changeset/beige-shoes-whisper.md diff --git a/.changeset/beige-shoes-whisper.md b/.changeset/beige-shoes-whisper.md new file mode 100644 index 00000000..e544c5d3 --- /dev/null +++ b/.changeset/beige-shoes-whisper.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': minor +--- + +Adds a configuration option to disable site indexing with Pagefind and the default search UI diff --git a/docs/src/content/docs/reference/configuration.mdx b/docs/src/content/docs/reference/configuration.mdx index 4808adb1..9e546dc5 100644 --- a/docs/src/content/docs/reference/configuration.mdx +++ b/docs/src/content/docs/reference/configuration.mdx @@ -411,6 +411,16 @@ When `false`, the colors provided by the active syntax highlighting theme are us When using custom themes and setting this to `true`, you must provide at least one dark and one light theme to ensure proper color contrast. ::: +### `pagefind` + +**type:** `boolean` +**default:** `true` + +Define whether Starlight’s default site search provider [Pagefind](https://pagefind.app/) is enabled. + +Set to `false` to disable indexing your site with Pagefind. +This will also hide the default search UI if in use. + ### `head` **type:** [`HeadConfig[]`](#headconfig) diff --git a/docs/src/content/docs/reference/overrides.md b/docs/src/content/docs/reference/overrides.md index 9bd6cc9c..fd4bc5d4 100644 --- a/docs/src/content/docs/reference/overrides.md +++ b/docs/src/content/docs/reference/overrides.md @@ -234,6 +234,10 @@ The default implementation includes logic for rendering logos defined in Starlig Component used to render Starlight’s search UI. The default implementation includes the button in the header and the code for displaying a search modal when it is clicked and loading [Pagefind’s UI](https://pagefind.app/). +When [`pagefind`](/reference/configuration/#pagefind) is disabled, the default search component will not be rendered. +However, if you override `Search`, your custom component will always be rendered even if the `pagefind` configuration option is `false`. +This allows you to add UI for alternative search providers when disabling Pagefind. + #### `SocialIcons` **Default component:** [`SocialIcons.astro`](https://github.com/withastro/starlight/blob/main/packages/starlight/components/SocialIcons.astro) diff --git a/packages/starlight/components/Header.astro b/packages/starlight/components/Header.astro index 51bf9a08..7042a800 100644 --- a/packages/starlight/components/Header.astro +++ b/packages/starlight/components/Header.astro @@ -1,4 +1,5 @@ --- +import config from 'virtual:starlight/user-config'; import type { Props } from '../props'; import { @@ -8,6 +9,12 @@ import { SocialIcons, ThemeSelect, } from 'virtual:starlight/components'; + +/** + * Render the `Search` component if Pagefind is enabled or the default search component has been overridden. + */ +const shouldRenderSearch = + config.pagefind || config.components.Search !== '@astrojs/starlight/components/Search.astro'; ---
@@ -15,7 +22,7 @@ import {
- + {shouldRenderSearch && }