From e1873834d4a4328084a9ac056a089ee5b8f13103 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Mon, 13 Jan 2025 11:47:55 +0100 Subject: Upgrade Pagefind to 1.3.0 and configure Pagefind logging levels (#2728) Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com> --- .changeset/long-pears-shop.md | 7 ++++ .changeset/young-plants-fetch.md | 5 +++ docs/src/content/docs/reference/configuration.mdx | 20 +++++++++- package.json | 2 +- .../__tests__/basics/config-errors.test.ts | 9 ++++- packages/starlight/components/Search.astro | 3 ++ packages/starlight/index.ts | 23 +++++++++-- .../starlight/integrations/virtual-user-config.ts | 1 + packages/starlight/package.json | 4 +- packages/starlight/schemas/pagefind.ts | 44 +++++++++++++++++++++ packages/starlight/utils/user-config.ts | 22 +++++++---- packages/starlight/virtual-internal.d.ts | 6 +++ pnpm-lock.yaml | 46 +++++++++++----------- 13 files changed, 153 insertions(+), 39 deletions(-) create mode 100644 .changeset/long-pears-shop.md create mode 100644 .changeset/young-plants-fetch.md create mode 100644 packages/starlight/schemas/pagefind.ts diff --git a/.changeset/long-pears-shop.md b/.changeset/long-pears-shop.md new file mode 100644 index 00000000..5bec6019 --- /dev/null +++ b/.changeset/long-pears-shop.md @@ -0,0 +1,7 @@ +--- +'@astrojs/starlight': minor +--- + +Updates minimum Pagefind dependency to v1.3.0, sets new defaults for Pagefind’s ranking options, and adds support for manually configuring the ranking options + +The new ranking option defaults have been evaluated against Starlight’s own docs to improve the quality of search results. See [“Customize Pagefind's result ranking”](https://pagefind.app/docs/ranking/) for more details about how they work. \ No newline at end of file diff --git a/.changeset/young-plants-fetch.md b/.changeset/young-plants-fetch.md new file mode 100644 index 00000000..556c973a --- /dev/null +++ b/.changeset/young-plants-fetch.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': minor +--- + +Fixes Pagefind logging to respect the Astro log level. When using Astro’s `--verbose` or `--silent` CLI flags, these are now respected by Pagefind as well. diff --git a/docs/src/content/docs/reference/configuration.mdx b/docs/src/content/docs/reference/configuration.mdx index f4ceb57d..28132f34 100644 --- a/docs/src/content/docs/reference/configuration.mdx +++ b/docs/src/content/docs/reference/configuration.mdx @@ -447,16 +447,32 @@ When using custom themes and setting this to `true`, you must provide at least o ### `pagefind` -**type:** `boolean` +**type:** boolean | PagefindOptions **default:** `true` -Define whether Starlight’s default site search provider [Pagefind](https://pagefind.app/) is enabled. +Configure Starlight’s default site search provider [Pagefind](https://pagefind.app/). Set to `false` to disable indexing your site with Pagefind. This will also hide the default search UI if in use. Pagefind cannot be enabled when the [`prerender`](#prerender) option is set to `false`. +Set `pagefind` to an object to configure the Pagefind search client. +See [“Customize Pagefind's result ranking”](https://pagefind.app/docs/ranking/) in the Pagefind documentation for more details about using the `pagefind.ranking` option to control how search result ranking is calculated. + +#### `PagefindOptions` + +```ts +interface PagefindOptions { + ranking?: { + pageLength?: number; + termFrequency?: number; + termSaturation?: number; + termSimilarity?: number; + }; +} +``` + ### `prerender` **type:** `boolean` diff --git a/package.json b/package.json index 627a5464..06ad3495 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ { "name": "/_astro/*.js", "path": "examples/basics/dist/_astro/*.js", - "limit": "23.5 kB", + "limit": "27 kB", "gzip": true }, { diff --git a/packages/starlight/__tests__/basics/config-errors.test.ts b/packages/starlight/__tests__/basics/config-errors.test.ts index ed0d7374..426f5ae2 100644 --- a/packages/starlight/__tests__/basics/config-errors.test.ts +++ b/packages/starlight/__tests__/basics/config-errors.test.ts @@ -63,7 +63,14 @@ test('parses valid config successfully', () => { "isUsingBuiltInDefaultLocale": true, "lastUpdated": false, "locales": undefined, - "pagefind": true, + "pagefind": { + "ranking": { + "pageLength": 0.1, + "termFrequency": 0.1, + "termSaturation": 2, + "termSimilarity": 9, + }, + }, "pagination": true, "prerender": true, "tableOfContents": { diff --git a/packages/starlight/components/Search.astro b/packages/starlight/components/Search.astro index e4398cdb..b5847608 100644 --- a/packages/starlight/components/Search.astro +++ b/packages/starlight/components/Search.astro @@ -76,6 +76,8 @@ if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash