Skip to content

Commit

Permalink
fix: Add multilang index
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Sep 26, 2024
1 parent 1997adb commit 9683346
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions esbuild/langs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export async function worker(outdir) {
self.language = function(lunr: any) {
${attach(lang)}
lunr.multiLanguage('en', '${lang}');
return (lunr as unknown as {[lang: string]: Builder.Plugin}).${lang} as Builder.Plugin;
};
`;
Expand Down Expand Up @@ -135,6 +137,8 @@ function imports(lang) {
// @ts-ignore
import stemmer from 'lunr-languages/lunr.stemmer.support';
// @ts-ignore
import multi from 'lunr-languages/lunr.multi';
// @ts-ignore
import lang from 'lunr-languages/lunr.${lang}';
${
['ja', 'jp'].includes(lang)
Expand All @@ -161,5 +165,6 @@ function attach(lang) {
lang(lunr);
${['ja', 'jp'].includes(lang) ? `tinyseg(lunr);` : ''}
${['th', 'hi', 'ta', 'sa', 'kn', 'te'].includes(lang) ? `wordcut(lunr);` : ''}
multi(lunr);
`;
}
4 changes: 3 additions & 1 deletion src/indexer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class Indexer {
const index = new Builder();

if (langs[lang]) {
index.use(langs[lang](lunr));
langs[lang](lunr);
// @ts-ignore
index.use(lunr.multiLanguage('en', lang));
}

index.ref('url');
Expand Down

0 comments on commit 9683346

Please sign in to comment.