Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ requests-per-second velocity gauge in the hero.
| ------------------ | ------------------------------------------------------------------------------------------------------------------------ |
| `npm install` | Install dependencies |
| `npm run dev` | Start the dev server at `localhost:4321` |
| `npm run build` | Build to `build/` and generate the Pagefind search index |
| `npm run build:website` | Build to `build/` and generate the Pagefind search index |
| `npm run preview` | Preview the production build locally |
| `npm run lint` | Lint with [Biome](https://biomejs.dev) |
| `npm run format` | Format with Biome (`format` to verify) |
| `npm run check` | Type-check via [`astro check`](https://docs.astro.build/en/reference/cli-reference/#astro-check) (run by CI on every PR) |

> Search only works against a production build (`npm run build`), because the
> Search only works against a production build (`npm run build:website`), because the
> Pagefind index is generated from the built HTML. In `dev` the search modal
> shows a graceful fallback message.
>
Expand Down Expand Up @@ -70,7 +70,7 @@ Docusaurus site:
The documentation is **not** stored in this repository — it lives in the
[`fastify/fastify`](https://github.com/fastify/fastify) repo and is fetched at
build time by [`scripts/fetch-docs.mjs`](scripts/fetch-docs.mjs), which runs
automatically via the `prebuild`/`predev` npm hooks.
as part of `npm run build:website`.

The script:

Expand Down
7 changes: 5 additions & 2 deletions src/components/Search.astro
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ import { withBase } from "~/lib/href";

let pagefind: any = null;
let loadFailed = false;
const pagefindUrl = withBase('/pagefind/pagefind.js');

async function ensurePagefind() {
if (pagefind || loadFailed) return pagefind;
try {
pagefind = await import(/* @vite-ignore */ `${import.meta.env.BASE_URL}/pagefind/pagefind.js`);
pagefind = await import(/* @vite-ignore */ pagefindUrl);
await pagefind.init?.();
} catch (e) {
} catch (error) {
pagefind = null;
loadFailed = true;
console.error(`Failed to load Pagefind from ${pagefindUrl}`, error);
hint?.classList.add('hidden');
fallback?.classList.remove('hidden');
}
Expand Down