Skip to content

Commit

Permalink
Switch to upstream @antora/lunr-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio committed Aug 31, 2023
1 parent 31a17de commit 0428a6e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Binary file removed antora-lunr-extension-1.0.0-alpha.6.tgz
Binary file not shown.
19 changes: 19 additions & 0 deletions lunr-tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,26 @@
// We extend the set of characters considered separators to include
// parentheses and commas.

const path = require('path');
const fs = require('fs');

module.exports.register = () => {
const lunr = require('lunr');
lunr.tokenizer.separator = /[\s\-(),]+/;
lunr.QueryLexer.termSeparator = lunr.tokenizer.separator;

// The lunr source code is vendored into the UI, and tokenization for search results
// is done client side, so we have to patch this file to fix tokenization too.
const patch = `(function () { globalThis.lunr.tokenizer.separator = ${lunr.tokenizer.separator.toString()}; })();`

const searchUiPath = path.join(
path.dirname(require.resolve('@antora/lunr-extension/package.json')),
'data/js/search-ui.js',
);

const searchUi = fs.readFileSync(searchUiPath, 'utf8');

if (!searchUi.includes(patch)) {
fs.writeFileSync(searchUiPath, searchUi + patch);
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"watch:local": "fgbg 'nodemon -e yml,adoc -w components -x yarn build:local' 'live-server build/site'"
},
"dependencies": {
"@antora/lunr-extension": "file:antora-lunr-extension-1.0.0-alpha.6.tgz",
"@antora/lunr-extension": "^1.0.0-alpha.8",
"antora": "^3.0.0",
"glob": "^7.1.4",
"js-yaml": "^3.13.1",
Expand Down
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@
pino-pretty "~7.3"
sonic-boom "~2.4"

"@antora/lunr-extension@file:antora-lunr-extension-1.0.0-alpha.6.tgz":
version "1.0.0-alpha.6"
resolved "file:antora-lunr-extension-1.0.0-alpha.6.tgz#c17caf483142236a85db8754b18e70185e2df17a"
"@antora/lunr-extension@^1.0.0-alpha.8":
version "1.0.0-alpha.8"
resolved "https://registry.npmjs.org/@antora/lunr-extension/-/lunr-extension-1.0.0-alpha.8.tgz#7a72afd3e890caebd6cfcb6933370a558a1d8b9f"
integrity sha512-vdBgW3rsvbnmA236kT2Dckh9n0Db5za2/WxiLnFLgZ05ZO1KJQa9+R2WHaIFuGE7bKKbY+lqfM/i3KiezbL9YQ==
dependencies:
cheerio "1.0.0-rc.10"
html-entities "~2.3"
Expand Down

0 comments on commit 0428a6e

Please sign in to comment.