From 9683346b192bfdee3a0ba6c4469a405326b45c48 Mon Sep 17 00:00:00 2001 From: 3y3 <3y3@ya.ru> Date: Thu, 26 Sep 2024 16:21:00 +0300 Subject: [PATCH] fix: Add multilang index --- esbuild/langs.mjs | 5 +++++ src/indexer/index.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/esbuild/langs.mjs b/esbuild/langs.mjs index 4c6a4cb..532ccd7 100644 --- a/esbuild/langs.mjs +++ b/esbuild/langs.mjs @@ -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; }; `; @@ -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) @@ -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); `; } diff --git a/src/indexer/index.ts b/src/indexer/index.ts index 48ffaa1..78aabaf 100644 --- a/src/indexer/index.ts +++ b/src/indexer/index.ts @@ -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');