From ea5772655274a3900310cb700836fdd2f6dba7cd Mon Sep 17 00:00:00 2001 From: Brian Mortenson Date: Thu, 7 Sep 2023 05:14:23 -0600 Subject: add option to docs schema to exclude a page from pagefind (#647) Co-authored-by: Chris Swithinbank --- .changeset/dull-mails-kiss.md | 5 +++++ .changeset/spicy-eggs-nail.md | 5 +++++ docs/src/content/docs/reference/frontmatter.md | 16 +++++++++++++++- packages/starlight/layout/Page.astro | 3 ++- packages/starlight/schema.ts | 3 +++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .changeset/dull-mails-kiss.md create mode 100644 .changeset/spicy-eggs-nail.md diff --git a/.changeset/dull-mails-kiss.md b/.changeset/dull-mails-kiss.md new file mode 100644 index 00000000..2f5bcd47 --- /dev/null +++ b/.changeset/dull-mails-kiss.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Fix translated 404 pages not being excluded from search results diff --git a/.changeset/spicy-eggs-nail.md b/.changeset/spicy-eggs-nail.md new file mode 100644 index 00000000..6924f42e --- /dev/null +++ b/.changeset/spicy-eggs-nail.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Add frontmatter option to exclude a page from Pagefind search results diff --git a/docs/src/content/docs/reference/frontmatter.md b/docs/src/content/docs/reference/frontmatter.md index 7ceb8344..7b305411 100644 --- a/docs/src/content/docs/reference/frontmatter.md +++ b/docs/src/content/docs/reference/frontmatter.md @@ -208,6 +208,20 @@ next: false --- ``` +### `pagefind` + +**type:** `boolean` +**default:** `true` + +Set whether this page should be included in the [Pagefind](https://pagefind.app/) search index. Set to `false` to exclude a page from search results: + +```md +--- +# Hide this page from the search index +pagefind: false +--- +``` + ### `sidebar` **type:** `{ label?: string; order?: number; hidden?: boolean; badge?: string | BadgeConfig }` @@ -246,7 +260,7 @@ sidebar: #### `hidden` -**type:** `boolean` +**type:** `boolean` **default:** `false` Prevents this page from being included in an autogenerated sidebar group. diff --git a/packages/starlight/layout/Page.astro b/packages/starlight/layout/Page.astro index 7b01c441..5dfcbe35 100644 --- a/packages/starlight/layout/Page.astro +++ b/packages/starlight/layout/Page.astro @@ -45,6 +45,7 @@ const tocConfig = !hasSidebar : config.tableOfContents; const hasToC = Boolean(tocConfig); const hasHero = Boolean(entry.data.hero); +const pagefindEnabled = entry.slug !== '404' && !entry.slug.endsWith('/404') && entry.data.pagefind !== false; --- } -
+
{/* TODO: Revisit how this logic flows. */} {entry.data.banner && } { diff --git a/packages/starlight/schema.ts b/packages/starlight/schema.ts index aae1cdd4..d0775e70 100644 --- a/packages/starlight/schema.ts +++ b/packages/starlight/schema.ts @@ -165,5 +165,8 @@ export function docsSchema() { content: z.string(), }) .optional(), + + /** Pagefind indexing for this page - set to false to disable. */ + pagefind: z.boolean().default(true), }); } -- cgit