靜態搜尋實戰:Pagefind 在網站專案的整合
透過 Pagefind 建立無後端 API 的站內搜尋。
核心觀念
Pagefind 在 build 階段建立索引,因此前台搜尋不需要額外 API 伺服器。
實作步驟
- 先完成
npm run build產出 HTML 與索引。 - 接著執行
pagefind --site dist建立索引。 - 在搜尋頁用
import('/pagefind/pagefind.js')進行查詢。
開發模式看不到結果怎麼辦?
因為 dev server 不會自動生成 Pagefind 索引,先執行 build + preview 即可。