跳过正文

Search

查看源码 编辑此页 (外部链接)
首次發表:

Built-in search is powered by Pagefind (外部链接), a static search library that serves results entirely in the browser with no external service needed.

Enabling search requires two steps: setting a config flag so Yore renders the search UI, and running Pagefind after every build to generate the search index. Both are required because the UI will not work without the index.

Step 1: Enable the search UI 此标题的链接

hugo.yaml
params:
  searchEnabled: true

Step 2: Generate the search index 此标题的链接

Pagefind reads the HTML files Hugo produces and builds a search index from them. Install Node.js (外部链接), then add Pagefind to your development dependencies:

npm install -D pagefind

Add the following scripts to package.json.

package.json
{
  "scripts": {
    "pagefind": "pagefind --site public",
    "build": "hugo --gc --minify && npm run pagefind",
    "dev": "hugo server"
  }
}

Finally, run npm run pagefind after the site is built.

重要

Include the indexing step in your deployment script (GitHub workflow, Cloudflare build script, etc.), otherwise search will not appear on the deployed site.

Set pageNoList: true in a page's front matter to exclude it from search results and list pages.

文章关联

无障碍设定

字体大小