{
  "id": "add-pagefind-search-to-astro",
  "type": "playbooks",
  "category": "playbooks",
  "locale": "fr",
  "url": "/fr/playbooks/add-pagefind-search-to-astro",
  "title": "Prompt-to-PR : Ajouter la recherche Pagefind à un site Astro",
  "description": "La SOP complète pour ajouter une recherche statique sans backend à un site Astro avec Pagefind — de la première invite à la description de la PR.",
  "tools": [
    "Cursor",
    "Claude Code"
  ],
  "stack": [
    "Astro",
    "TypeScript"
  ],
  "tags": [
    "search",
    "astro",
    "pagefind"
  ],
  "difficulty": "easy",
  "updated": "2026-06-08",
  "markdown": "Un guide complet : le besoin, la première invite, les modifications attendues, la revue, les tests, les échecs probables, l'invite de correction et la description de la PR.\n\n## 1. Besoin\n\nAjouter une recherche en texte intégral à un site Astro statique sans serveur et sans base de données.\n\n## 2. Première invite\n\n```txt title=\"First Prompt\"\nAdd Pagefind search to this Astro static site.\n\n- Add `pagefind` as a devDependency.\n- Update the build script to run `astro build && pagefind --site dist`.\n- Create a `/search` page that mounts Pagefind UI from `/pagefind/pagefind-ui.js`.\n- Mark the main article body with `data-pagefind-body` and add\n  `data-pagefind-ignore` to nav/footer.\n- Do not introduce a server adapter; this stays fully static.\n```\n\n## 3. Modifications de fichiers attendues\n\n```txt\npackage.json                 (build script)\nsrc/pages/search.astro       (new)\nsrc/layouts/BaseLayout.astro (data-pagefind-ignore on chrome)\n```\n\n## 4. Liste de vérification pour la revue\n\n- Le script de build exécute Pagefind *après* `astro build`.\n- La page de recherche se dégrade gracieusement dans `astro dev` (l'index n'existe qu'après le build).\n- La navigation et le pied de page sont exclus de l'index.\n\n## 5. Commandes de test\n\n```bash\nbun run build\nbun run preview\n# open /search and query a known term\n```\n\n## 6. Échecs courants\n\n- Monter l'interface Pagefind avant le chargement du script → `PagefindUI is not defined`.\n- Exécuter Pagefind avant le build, donc il n'indexe rien.\n\n## 7. Invite de correction\n\n```txt title=\"Fix Prompt\"\nPagefind indexed an empty site. Ensure the build runs `astro build` first,\nthen `pagefind --site dist`, and that the UI script loads before init.\n```\n\n## 8. Description de la PR\n\n```md title=\"PR description\"\nAdd static full-text search via Pagefind. Indexes `dist` at build time;\nno backend. New `/search` page; nav/footer excluded from the index.\n```"
}