v2.0.2
Search
npm run build writes a search index under site/api/ and bundles a React runtime that mounts
into the <Search /> placeholder or [data-canopy-search]. Works (IIIF manifests) and pages (MDX
files) share a single FlexSearch store so filters and type tabs stay in sync.
Data sources
- Works — every manifest pulled from
collectionURIs becomes atype: 'work'record withid,title, andhrefpointing at/works/<slug>.html. Metadata fields listed insearch.index.metadataare flattened for indexing. - Pages — MDX files contribute
type: 'page'records when they have no front matter or when they explicitly settype(orsearchType). Addsearch: falseto opt out. OptionalsearchSummaryandsearchSummaryMarkdownfields override the teaser, anddescriptiondoes where neither is set;imageshows beside the result (Customize search).
A page is found by its prose: its headings, paragraphs, lists, quotes and table cells, and the
words its components hold. Code blocks, imports, {expressions} and the attributes of its
components are left out. Without a teaser, its result shows the passage around the words
searched for.
packages/app/lib/build/search-index.js combines the records and keeps IDs stable between
search-index.json (FlexSearch input) and search-records.json (display data).
How a search matches
The search page and the header's field find the same things, the same way:
- A word is found by its beginning:
manufinds "manuscript",mafinds "map". - Case and accents do not matter:
haridwarfinds "Haridwār", andMéxicofinds "Mexico". - Every word of a query must be found:
seated womanfinds only what has both words. - A record is found by its title, then its metadata, summary and annotation, and a match in the title ranks first.
A visitor's browser builds the index the first time they search and keeps it until the site's index changes, so later pages search at once.
The header's field
The search field in the header suggests works and pages as a visitor types, grouped by type, and says how many it found to screen readers. The down arrow moves into the suggestions, the up arrow and Escape come back to the field, and Enter on the field opens the search page. ⌘K (Ctrl K on Windows and Linux) goes to the field from anywhere on the page. A page loads nothing for search until its field is used.
On the search page itself, the field drives the page's results instead.
Page composition
content/search/_layout.mdx lays out the search page, and every site needs one (the templates
ship it). Place the search components in it anywhere, in any markup: <SearchTabs />,
<SearchSummary /> and <SearchResults /> read from the same results. The header's search
field drives them. The layout receives the page's details as props.page, its title among them.
<div className="canopy-search-results"> <h1>{props.page?.title || "Search"}</h1> <SearchTabs /> <SearchSummary /> <SearchResults /></div>Open the layout with an h1, as above: each page's result is titled by a heading one level
below the last heading before the results, h2 under the page's h1. Set it yourself with
<SearchResults headingLevel={3} />.
Page metadata
Configure the browser <title> and meta description via search.page inside canopy.yml. A
search page in another of the site's languages takes that language's word for "search" from its
locale.yml (common.nouns.search) as its title.
search: page: title: Discover everything description: Browse every work and story in one place.Tabs, layouts, and templates
Control the rendered tabs and markup via search.results in canopy.yml:
search: results: work: layout: grid # grid | list result: figure # figure | article page: layout: list result: article tabs: order: - work - pagelayoutswitches between the masonry grid (usesreact-masonry-css) and a stacked list.resultpicks the MDX partial that renders each item. Define_result-figure.mdxor_result-article.mdxundercontent/search/to override the defaults. Each file receives the record (props.record), the active query, and helper props for badges or metadata.tabs.orderreorders tabs without redefininglayout/result. Types omitted fromresultsinherit the defaultgrid+figurecombo.
The tabs are one stop for the keyboard: the left and right arrows, Home and End move between them, and the results follow at once.
Filtering and URL state
The runtime watches ?q and ?type query params, so deep links remain stable when you switch
between tabs or refine a search. When you add more record types via front matter
(searchType: example), include them in search.results and tabs.order to expose dedicated tabs.
Styling hooks
- Use the
.canopy-searchclass (root element) to add custom spacing or background treatments inapp/styles/main.css. - Override button or input styles globally via the Tailwind preset or your own CSS variables in
@theme. - When you need different markup for specific record types, create additional templates under
content/search/and branch based onrecord.typeinside the MDX.
Debugging tips
- Inspect
site/api/search-index.jsonto confirm front-matter summaries and metadata labels are being indexed. - When the browser console logs
Dynamic require of 'react' is not supported, make sure the UI build marksreact,react-dom,react-dom/client,react-masonry-css, andflexsearchas externals (the repository is already configured this way). - Delete
.cache/search(if present) plussite/api/search-*and rebuild when you change record shapes. - When the search page says "Search unavailable.", its runtime could not load the index; the browser console says why.
- Add
?searchDebugto the search page's address to log how long the index took to build, or to load from the browser's cache.
Metadata browse
Canopy builds /metadata automatically. It groups the metadata labels you list in canopy.yml
(metadata array) and renders links to every unique value found across the ingested manifests. Each
link jumps directly to search results filtered to that label/value pair.
metadata: - Subject - Creator - Date - LocationDuring the IIIF build, Canopy generates /api/facet/<label>/<value>.json collections for those
labels. The metadata page uses the files to calculate counts and to build the links used elsewhere
(home sliders, related items, search filters).
Page anatomy
- Intro copy —
content/metadata/index.mdxcontrols the opening paragraph and any contextual guidance you want to provide to visitors. - Facet sections — For each configured label Canopy shows the heading and a list of values,
ordered by descending occurrence. Each value links to
/search?type=work&label=<label>&value=<value>. - Counts — Values display the number of works that match the label/value pair so users can gauge scale before clicking through.
Editing tips
- Keep facet labels short and consistent; the UI uses the label verbatim as the section heading.
- Remove labels from
canopy.ymlwhen you stop using them to avoid generating unused/api/facet/**files. - Pair metadata browse sections with MDX essays that explain curatorial choices. Cite those works
via
referencedManifestsso the relationship flows back to individual work pages.