From 7eb8db76d90eab20141e7a5a2a8ce6c1edefd252 Mon Sep 17 00:00:00 2001 From: Yufei Huang Date: Tue, 24 Oct 2023 14:18:27 +0800 Subject: [PATCH] fix: Cannot load unregistered function: stemmer-ru fixes #8830 --- samples/seed/template/public/main.js | 2 ++ templates/modern/src/search-worker.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/samples/seed/template/public/main.js b/samples/seed/template/public/main.js index 9e8965c85de..3b6ceb77ded 100644 --- a/samples/seed/template/public/main.js +++ b/samples/seed/template/public/main.js @@ -13,7 +13,9 @@ export default { title: 'Twitter' } ], + lunrLanguages: ['en', 'ru'], configureHljs: function (hljs) { hljs.registerLanguage('bicep', bicep); }, } + diff --git a/templates/modern/src/search-worker.ts b/templates/modern/src/search-worker.ts index d6958e4e6c1..362bd8acb68 100644 --- a/templates/modern/src/search-worker.ts +++ b/templates/modern/src/search-worker.ts @@ -26,13 +26,6 @@ async function loadIndexCore() { const data = await res.json() as { [key: string]: SearchHit } const cache = createStore('docfx', 'lunr') - if (etag) { - const value = JSON.parse(await get('index', cache) || '{}') - if (value && value.etag === etag) { - return { index: lunr.Index.load(value), data } - } - } - const { lunrLanguages, configureLunr } = await import('./main.js').then(m => m.default) as DocfxOptions if (lunrLanguages && lunrLanguages.length > 0) { @@ -41,6 +34,13 @@ async function loadIndexCore() { await Promise.all(lunrLanguages.map(initLanguage)) } + if (etag) { + const value = JSON.parse(await get('index', cache) || '{}') + if (value && value.etag === etag) { + return { index: lunr.Index.load(value), data } + } + } + const index = lunr(function() { lunr.tokenizer.separator = /[\s\-.()]+/