Prompt-to-PR : Ajouter la recherche Pagefind à un site Astro
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.
CursorClaude Code AstroTypeScript
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.
1. Besoin
Ajouter une recherche en texte intégral à un site Astro statique sans serveur et sans base de données.
2. Première invite
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. Modifications de fichiers attendues
package.json (build script)src/pages/search.astro (new)src/layouts/BaseLayout.astro (data-pagefind-ignore on chrome)4. Liste de vérification pour la revue
- Le script de build exécute Pagefind après
astro build. - La page de recherche se dégrade gracieusement dans
astro dev(l’index n’existe qu’après le build). - La navigation et le pied de page sont exclus de l’index.
5. Commandes de test
bun run buildbun run preview# open /search and query a known term6. Échecs courants
- Monter l’interface Pagefind avant le chargement du script →
PagefindUI is not defined. - Exécuter Pagefind avant le build, donc il n’indexe rien.
7. Invite de correction
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. Description de la PR
Add static full-text search via Pagefind. Indexes `dist` at build time;no backend. New `/search` page; nav/footer excluded from the index.