diff options
author | Chris Swithinbank | 2023-11-29 20:31:39 +0100 |
---|---|---|
committer | GitHub | 2023-11-29 20:31:39 +0100 |
commit | 7c0b8cb334c501678f7ab87cce372cddfdde34ed (patch) | |
tree | 788163ab551571667f4f83b0b1d1ff30a1b0da05 | |
parent | e5a863a98b2e5335e122ca440dcb84e9426939b4 (diff) | |
download | IT.starlight-7c0b8cb334c501678f7ab87cce372cddfdde34ed.tar.gz IT.starlight-7c0b8cb334c501678f7ab87cce372cddfdde34ed.tar.bz2 IT.starlight-7c0b8cb334c501678f7ab87cce372cddfdde34ed.zip |
Add a `pagefind` boolean flag to user config (#1144)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
-rw-r--r-- | .changeset/beige-shoes-whisper.md | 5 | ||||
-rw-r--r-- | docs/src/content/docs/reference/configuration.mdx | 10 | ||||
-rw-r--r-- | docs/src/content/docs/reference/overrides.md | 4 | ||||
-rw-r--r-- | packages/starlight/components/Header.astro | 9 | ||||
-rw-r--r-- | packages/starlight/index.ts | 1 | ||||
-rw-r--r-- | packages/starlight/utils/user-config.ts | 7 |
6 files changed, 35 insertions, 1 deletions
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'; --- <div class="header sl-flex"> @@ -15,7 +22,7 @@ import { <SiteTitle {...Astro.props} /> </div> <div class="sl-flex"> - <Search {...Astro.props} /> + {shouldRenderSearch && <Search {...Astro.props} />} </div> <div class="sl-hidden md:sl-flex right-group"> <div class="sl-flex social-icons"> diff --git a/packages/starlight/index.ts b/packages/starlight/index.ts index b299b22d..b40e0223 100644 --- a/packages/starlight/index.ts +++ b/packages/starlight/index.ts @@ -77,6 +77,7 @@ export default function StarlightIntegration(opts: StarlightUserConfig): AstroIn }, 'astro:build:done': ({ dir }) => { + if (!userConfig.pagefind) return; const targetDir = fileURLToPath(dir); const cwd = dirname(fileURLToPath(import.meta.url)); const relativeDir = relative(cwd, targetDir); diff --git a/packages/starlight/utils/user-config.ts b/packages/starlight/utils/user-config.ts index a026c216..9a581f3f 100644 --- a/packages/starlight/utils/user-config.ts +++ b/packages/starlight/utils/user-config.ts @@ -190,6 +190,13 @@ const UserConfigSchema = z.object({ */ expressiveCode: ExpressiveCodeSchema(), + /** + * Define whether Starlight’s default site search provider Pagefind is enabled. + * Set to `false` to disable indexing your site with Pagefind. + * This will also hide the default search UI if in use. + */ + pagefind: z.boolean().default(true), + /** Specify paths to components that should override Starlight’s default components */ components: ComponentConfigSchema(), |