import { d as IndexedDocument } from './types-DZE2UBNA.js'; /** * `@icjia/pdf-search-index/pagefind` — build-step helper for the * [Pagefind](https://pagefind.app/) search engine. * * **When to use this instead of `/fuse` or `/flexsearch`.** Pagefind is * fundamentally different from both: it operates on a chunked * on-demand index rather than an in-memory index loaded up-front. For * five-figure+ corpora it's the only viable option that doesn't pay * the full-index download cost on first load. * * < 2,500 docs → Fuse.js * 2,500 – 10,000 docs → FlexSearch * **10,000+ docs** → **Pagefind** * * **How Pagefind works.** Pagefind expects an HTML site to crawl. It * walks the rendered HTML, builds its inverted index, and partitions it * into chunks the browser loads only when a query needs them. The * resulting bundle on the wire is tiny (the `pagefind.js` client is * ~50 KB gz; individual query chunks are 5–20 KB each). * * **What this helper does.** Our package outputs JSON document rows. * Pagefind expects HTML pages. `emitPagefindHTML` is the bridge: * given `IndexedDocument[]` rows, it writes one HTML page per document * into a configured output directory. Each page contains the document's * extracted text inside a `
` wrapper. After * running this helper, the consumer invokes the Pagefind CLI against * the output dir, which produces the chunked index files. * * **Usage:** * * ```ts * // build step (Node) * import { emitPagefindHTML } from '@icjia/pdf-search-index/pagefind'; * import { indexDocuments } from '@icjia/pdf-search-index'; * * const rows = await indexDocuments(urls); * await emitPagefindHTML(rows, { * outDir: 'public/pagefind-source', * // Each row becomes pageFind-source/.html. * }); * ``` * * Then add to `package.json` scripts: * * ```json * "build:search": "node build-index.mjs && pagefind --site public --output-subdir _pagefind" * ``` * * Pagefind crawls `public/` (which includes the emitted * `pagefind-source/*.html`) and writes the chunked index to * `public/_pagefind/`. Consumer page loads that via the standard * `