Search
Quick reference
- Search is provided by
@easyops-cn/docusaurus-search-local, configured indocusaurus.config.jsunderthemes. - It's a local/offline index built at build time — no external service (e.g. Algolia) is involved, and there's nothing to provision or pay for.
docsRouteBasePathlists every route the indexer should crawl:docs,samples,portfolio,resume,about. Blog and standalone pages are included viaindexBlog/indexPages, not this list.- Search does not work under
npm start— it only builds in a production build (npm run build). Usenpm run build && npm run serveto test it locally.
Configuration
themes: [
'docusaurus-theme-zoom-image',
[
require.resolve("@easyops-cn/docusaurus-search-local"),
{
hashed: true,
docsRouteBasePath: ["docs", "samples", "portfolio", "resume", "about"],
docsDir: [],
indexBlog: true,
indexPages: true, // about, portfolio, resume
highlightSearchTermsOnTargetPage: true,
ignoreFiles: [/markdown-page/],
},
],
],
hashed: truefingerprints the generated search index filename so it busts cache correctly across deploys.docsRouteBasePathtells the plugin which route prefixes to crawl for content. This site uses it for more than just docs:portfolio,resume, andaboutare standalone pages undersrc/pages/, not a docs plugin instance, but listing their routes here gets them indexed too.docsDir: []— on a typical site this maps eachdocsRouteBasePathentry to a source folder on disk (e.g.docsDir: ["docs", "samples"]). Here it's left empty:docsandsamples(theuserGuidedocs plugin instance registered inplugins) are both discovered automatically, andportfolio/resume/aboutaren't doc folders at all, so there's no folder to map them to.indexBlog: trueindexes blog posts under/blog.indexPages: trueindexes standalone pages insrc/pages/(About, Portfolio, Resume) — this is what actually makes those pages searchable, in combination with their routes being listed indocsRouteBasePath.highlightSearchTermsOnTargetPage: truehighlights the matched term on the page you land on after clicking a search result.ignoreFiles: [/markdown-page/]excludessrc/pages/markdown-page.mdx(a leftover Docusaurus boilerplate page) from the index.
Why this plugin instead of Algolia DocSearch
Algolia DocSearch requires an external, hosted index (either Algolia's free DocSearch program, which has its own application/approval process, or a self-managed Algolia account) and a secret key stored outside the repo. @easyops-cn/docusaurus-search-local builds its index entirely at npm run build time and ships it as a static asset alongside the rest of the site, so it needs no external account, no API keys, and works the same on any static host — which fits a site deployed as a plain static build.
Testing search locally
Search only works against the production build — the local index is generated during docusaurus build, not docusaurus start:
npm run build && npm run serve
Verify the search box returns results from docs, blog posts, and the About/Portfolio/Resume pages before deploying. Deployment itself is unchanged — see Deployment.
Adding a new section to the index
If a new standalone page or docs instance is added under src/pages/ or as a new docs plugin instance, add its route to docsRouteBasePath (and, for a real docs plugin instance with its own folder, the matching entry in docsDir) so it gets crawled.