Skip to content

Improve the search bar in the html documentation#4417

Open
d-torrance wants to merge 5 commits into
Macaulay2:developmentfrom
d-torrance:lunr.js
Open

Improve the search bar in the html documentation#4417
d-torrance wants to merge 5 commits into
Macaulay2:developmentfrom
d-torrance:lunr.js

Conversation

@d-torrance

Copy link
Copy Markdown
Member

We use lunr.js to power the search bar in the html documentation, which currently just sends folks to Google.

We add a couple new JavaScript files to the Style package, one to power the search and one containing an index constructed by the calls to installPackage during the build.

In addition, there's a new workflow that I'll plan on running close to each release to update the search index file in the repository (and also the prism.js highlighting symbols while we're at it).,

Here it is in action: https://d-torrance.github.io/M2

AI Disclosure

The code was almost completely written by Claude with lots of human oversight.

d-torrance and others added 3 commits June 4, 2026 15:52
Add lunr ^2.3.9 as an npm dependency with a copy rule in package.json,
and check in the resulting lunr.min.js alongside prism.js and katex.
The MIT license is embedded in the file header.

Run `npm install` in M2/Macaulay2/packages/Style to update.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- search.js: builds a lunr index on page load from window.M2SearchData,
  wires up #search-input to show a paginated dropdown (10 results at a
  time, "Show N more..." button, smooth scroll, "No results found."
  message, closes on outside click).  Appends * to each search term for
  prefix matching as you type.
- doc.css: styles for the search container, results dropdown, result
  rows (name / package / tagline), "show more" button, no-results message
- html.m2: load lunr.min.js, search-data.js, and search.js in defaultHEAD
- installPackage.m2: replace the Google search form in the button bar
  with a local #search-input / #search-results container

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add installSearchData(), called at the end of installHTML(), which
appends an Object.assign block to {Style}/search-data.js for every
non-undocumented, non-secondary tag in the package.  Each record
stores id, name, package, tagline, and path (relative to the Style
directory so it resolves correctly from any page depth).

Style is always the first package installed in a full docs build, so
its install clears any existing search-data.js to ensure each build
starts fresh without duplicates — no build system cooperation needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
d-torrance and others added 2 commits June 6, 2026 09:26
Adds a workflow_dispatch workflow that builds M2 from source, then
regenerates and commits the two sets of generated files in the Style
package:

  - prism.js / prism.js.LICENSE.txt  via make -C Macaulay2/editors prism/prism.js
  - search-data.js / search-data.json via make (install-packages)

Run via Actions → "Update generated Style assets" → Run workflow,
selecting the branch to update.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move ignore-words and skip options out of lint.yml into a .codespellrc
config file so the lint command stays clean.  Also skip lunr.min.js,
whose minified variable names trigger false positives.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@joel-dodge

Copy link
Copy Markdown
Contributor

I tested this a bit via the link in the description. The UX is very nice and e.g. searching for "modules" turned up all the nodes I know of that I wanted to see (within a page or two).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants