Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0527457
wip: Add 2 new propreties for index merging
XREvo Feb 4, 2025
6b0546c
wip: Add missing properties for mergeIndex
XREvo Feb 4, 2025
0faf2be
docs: Update pagefind doc reference
XREvo Feb 5, 2025
ebabab1
docs: Remove unnecessary whitespace before colon
XREvo Feb 6, 2025
6b4fa0f
docs: revert to double whitespace
XREvo Feb 6, 2025
c2b802f
docs: Remove unnecessary properties
XREvo Feb 6, 2025
080be3c
feat: Remove unnecessary properties
XREvo Feb 6, 2025
4c78093
feat: Convert nullish to optional
XREvo Feb 6, 2025
dac389f
docs: Revert invalid property change
XREvo Feb 6, 2025
10d9967
docs: Revert to let translators manage them
XREvo Feb 6, 2025
7dd2fd7
feat: Use a record for mergeFilter type
XREvo Feb 7, 2025
6563d55
fix: Wording typo
XREvo Feb 13, 2025
4741df5
fix: Wording typo
XREvo Feb 13, 2025
7cb26c5
fix: Closing lines of comments
XREvo Feb 13, 2025
042dbc1
fix: Link to doc
XREvo Feb 13, 2025
c0728dd
fix: Link to doc
XREvo Feb 13, 2025
bead418
fix: Link to doc
XREvo Feb 13, 2025
faa9d33
fix: Doc comment
XREvo Feb 13, 2025
c50177a
fix: Remove useless documentation
XREvo Feb 13, 2025
be6f86a
fix: Remove link to pagefind's code
XREvo Feb 13, 2025
ab8a526
fix: Error in TS documentation
XREvo Feb 13, 2025
a11d499
fix: Wording in TS doc
XREvo Feb 13, 2025
fba1216
fix: Typing in ref doc
XREvo Feb 13, 2025
0ff6148
`pnpm format`
delucis Feb 13, 2025
5ba81e3
Fix `mergeIndex` type in docs
delucis Feb 13, 2025
bd1049a
Merge branch 'main' into main
delucis Feb 13, 2025
97a4f6f
Add changeset
delucis Feb 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dry-geese-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/starlight": minor
---

Adds support for Pagefind’s multisite search features
21 changes: 19 additions & 2 deletions docs/src/content/docs/reference/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,10 @@ 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.
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
- See [“Searching multiple sites”](https://pagefind.app/docs/multisite/) in the Pagefind documentation for more details about using the `pagefind.mergeIndex` option to control how to search accros multiple sites

#### `PagefindOptions`

Expand All @@ -470,6 +472,21 @@ interface PagefindOptions {
termSaturation?: number;
termSimilarity?: number;
};
indexWeight?: number;
mergeIndex?: Array<{
bundlePath: string;
indexWeight?: number;
basePath?: string;
baseUrl?: string;
mergeFilter?: Record<string, string | string[]>;
language?: string;
ranking?: {
pageLength?: number;
termFrequency?: number;
termSaturation?: number;
termSimilarity?: number;
};
}>;
}
```

Expand Down
130 changes: 97 additions & 33 deletions packages/starlight/schemas/pagefind.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,107 @@
import { z } from 'astro/zod';

const indexWeightSchema = z.number().nonnegative().optional();
const pagefindRankingWeightsSchema = z.object({
/**
* Set Pagefind’s `pageLength` ranking option.
*
* The default value is `0.1` and values must be in the range `0` to `1`.
*
* @see https://pagefind.app/docs/ranking/#configuring-page-length
*/
pageLength: z.number().min(0).max(1).default(0.1),
/**
* Set Pagefind’s `termFrequency` ranking option.
*
* The default value is `0.1` and values must be in the range `0` to `1`.
*
* @see https://pagefind.app/docs/ranking/#configuring-term-frequency
*/
termFrequency: z.number().min(0).max(1).default(0.1),
/**
* Set Pagefind’s `termSaturation` ranking option.
*
* The default value is `2` and values must be in the range `0` to `2`.
*
* @see https://pagefind.app/docs/ranking/#configuring-term-saturation
*/
termSaturation: z.number().min(0).max(2).default(2),
/**
* Set Pagefind’s `termSimilarity` ranking option.
*
* The default value is `9` and values must be greater than or equal to `0`.
*
* @see https://pagefind.app/docs/ranking/#configuring-term-similarity
*/
termSimilarity: z.number().min(0).default(9),
});
const pagefindIndexOptionsSchema = z.object({
/**
* Overrides the URL path that Pagefind uses to load its search bundle
*/
basePath: z.string().optional(),
/**
* Appends the given baseURL to all search results. May be a path, or a full domain
*/
baseUrl: z.string().optional(),
/**
* Multiply all rankings for this index by the given weight.
*
* @see https://pagefind.app/docs/multisite/#changing-the-weighting-of-individual-indexes
*/
indexWeight: indexWeightSchema,
/**
* Apply this filter configuration to all search results from this index.
*
* Only applies in multisite setups.
*
* @see https://pagefind.app/docs/multisite/#filtering-results-by-index
*/
mergeFilter: z.record(z.string(), z.string().or(z.array(z.string()).nonempty())).optional(),
/**
* Language of this index.
*
* @see https://pagefind.app/docs/multisite/#merging-a-specific-language-index
*/
language: z.string().optional(),
/**
* Configure how search result rankings are calculated by Pagefind.
*/
ranking: pagefindRankingWeightsSchema.optional(),
});

const pagefindSchema = z.object({
/**
* Configure how search results from the current website are weighted by Pagefind
* compared to results from other sites when using the `mergeIndex` option.
*
* @see https://pagefind.app/docs/multisite/#changing-the-weighting-of-individual-indexes
*/
indexWeight: indexWeightSchema,
/** Configure how search result rankings are calculated by Pagefind. */
ranking: z
.object({
/**
* Set Pagefind’s `pageLength` ranking option.
*
* The default value is `0.1` and values must be in the range `0` to `1`.
*
* @see https://pagefind.app/docs/ranking/#configuring-page-length
*/
pageLength: z.number().min(0).max(1).default(0.1),
/**
* Set Pagefind’s `termFrequency` ranking option.
*
* The default value is `0.1` and values must be in the range `0` to `1`.
*
* @see https://pagefind.app/docs/ranking/#configuring-term-frequency
*/
termFrequency: z.number().min(0).max(1).default(0.1),
/**
* Set Pagefind’s `termSaturation` ranking option.
*
* The default value is `2` and values must be in the range `0` to `2`.
*
* @see https://pagefind.app/docs/ranking/#configuring-term-saturation
*/
termSaturation: z.number().min(0).max(2).default(2),
ranking: pagefindRankingWeightsSchema.default({}),
/**
* Configure how search indexes from different sites are merged by Pagefind.
*
* @see https://pagefind.app/docs/multisite/#searching-additional-sites-from-pagefind-ui
*/
mergeIndex: z
.array(
/**
* Set Pagefind’s `termSimilarity` ranking option.
*
* The default value is `9` and values must be greater than or equal to `0`.
* Each entry of this array represents a `PagefindIndexOptions` from pagefind.
*
* @see https://pagefind.app/docs/ranking/#configuring-term-similarity
* @see https://github.com/CloudCannon/pagefind/blob/v1.3.0/pagefind_web_js/lib/coupled_search.ts#L549
*/
termSimilarity: z.number().min(0).default(9),
})
.default({}),
pagefindIndexOptionsSchema.extend({
/**
* Set Pagefind’s `bundlePath` mergeIndex option.
*
* @see https://pagefind.app/docs/multisite/#searching-additional-sites-from-pagefind-ui
*/
bundlePath: z.string(),
})
)
.optional(),
});

export const PagefindConfigSchema = () => pagefindSchema;
Expand Down