Skip to main content

Search

The search feature provides full-text site search powered by Pagefind. It includes a search dialog triggered from the nav bar or via keyboard shortcut, and automatic search index building as a post-build step.

How it works

  1. After each production build, the theme runs Pagefind to index all built HTML pages.
  2. The nav bar includes a search button (magnifying glass icon).
  3. Clicking the button or pressing Cmd+K (Ctrl+K on Windows/Linux) opens a search dialog.
  4. Results are fetched from the Pagefind index and displayed with highlighted matches.

Search is enabled by default. The theme integration builds the Pagefind index, and the nav bar shows the search button automatically.

You need pagefind installed as a dev dependency in your project:

pnpm add -D pagefind

To disable search, pass search: false to the theme integration, which skips the index build (and the check that pagefind is installed):

// astro.config.ts
universityTheme({ search: false });

The nav’s search button is controlled separately: pass search={false} to BaseLayout or Nav to hide it, on its own or alongside the integration option.

<BaseLayout title="My Page" search={false}> ... </BaseLayout>

The Nav component accepts a search prop:

Prop Type Default Description
name * string --- Site name — rendered as a text wordmark when no logo is provided, and used as alt text for the logo when one is.
links NavLink[] [] Navigation links displayed in the top bar.
search boolean true Whether to show the search button and dialog.
logo ImageMetadata --- Logo image (light mode). When omitted, the site name renders as a text wordmark instead.
logoDark ImageMetadata --- Logo image (dark mode). Only used when `logo` is also provided.
logoCompact ImageMetadata --- Compact logo (e.g. a crest or monogram) swapped in below the mobile breakpoint, where a wide horizontal lockup would wrap the nav bar. Only used when `logo` is also provided; when omitted the full logo is shown at every width.
logoCompactDark ImageMetadata --- Compact logo (dark mode). Only used when `logoCompact` is provided.
homeHref string --- Where the logo links (default the site base).
labels Partial<ThemeLabels> --- Translations of the nav's labels; any left out stay English.

Keyboard shortcuts

Development vs production

Search only works against a built site. During development (pnpm dev), the search dialog will open but no results will be available because the Pagefind index doesn’t exist yet.

To test search locally, build and then preview:

pnpm build
pnpm preview

Notes