# De prompt a PR: Agregar búsqueda Pagefind a un sitio Astro

> El SOP completo para agregar búsqueda estática sin backend a un sitio Astro con Pagefind, desde el primer prompt hasta la descripción del PR.

**Type:** Playbook  
**Tools:** Cursor, Claude Code  
**Stack:** Astro, TypeScript  
**Difficulty:** easy  
**Updated:** 2026-06-08

---

Un manual completo: requisito, primer prompt, cambios esperados, revisión, pruebas,
posibles fallos, prompt de corrección y la descripción del PR.

## 1. Requisito

Agregar búsqueda de texto completo a un sitio Astro estático sin servidor ni base de datos.

## 2. Primer prompt

```txt title="First Prompt"
Add Pagefind search to this Astro static site.

- Add `pagefind` as a devDependency.
- Update the build script to run `astro build && pagefind --site dist`.
- Create a `/search` page that mounts Pagefind UI from `/pagefind/pagefind-ui.js`.
- Mark the main article body with `data-pagefind-body` and add
  `data-pagefind-ignore` to nav/footer.
- Do not introduce a server adapter; this stays fully static.
```

## 3. Cambios de archivo esperados

```txt
package.json                 (build script)
src/pages/search.astro       (new)
src/layouts/BaseLayout.astro (data-pagefind-ignore on chrome)
```

## 4. Lista de verificación de revisión

- El script de build ejecuta Pagefind *después* de `astro build`.
- La página de búsqueda degrada correctamente en `astro dev` (el índice solo existe post-build).
- Nav/footer están excluidos del índice.

## 5. Comandos de prueba

```bash
bun run build
bun run preview
# open /search and query a known term
```

## 6. Fallos comunes

- Montar la UI de Pagefind antes de que cargue el script → `PagefindUI is not defined`.
- Ejecutar Pagefind antes del build, por lo que no indexa nada.

## 7. Prompt de corrección

```txt title="Fix Prompt"
Pagefind indexed an empty site. Ensure the build runs `astro build` first,
then `pagefind --site dist`, and that the UI script loads before init.
```

## 8. Descripción del PR

```md title="PR description"
Add static full-text search via Pagefind. Indexes `dist` at build time;
no backend. New `/search` page; nav/footer excluded from the index.
```