From 228c46084d53ddd812e7f5c352e77b9c4e087b65 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 4 Nov 2024 18:39:47 +0100 Subject: [PATCH 1/2] Update categories --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 747b6d01..48cb83aa 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "l10n": "./l10n", "categories": [ "AI", - "Other" + "Visualization" ], "keywords": [ "Front Matter", From 17164df11f351949a7ac6fba56d60cfda01a87aa Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 4 Nov 2024 19:37:00 +0100 Subject: [PATCH 2/2] Update fuse options --- src/listeners/panel/FieldsListener.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/listeners/panel/FieldsListener.ts b/src/listeners/panel/FieldsListener.ts index ef68963f..65f673b3 100644 --- a/src/listeners/panel/FieldsListener.ts +++ b/src/listeners/panel/FieldsListener.ts @@ -46,11 +46,14 @@ export class FieldsListener extends BaseListener { } PagesListener.getPagesData(false, async (pages) => { + const fuseKeys: Fuse.FuseOptionKey[] = [{ name: 'fmContentType', weight: 1 }]; + + if (isLocaleEnabled && data.sameLocale) { + fuseKeys.push({ name: 'fmLocale.locale', weight: 1 }); + } + const fuseOptions: Fuse.IFuseOptions = { - keys: [ - { name: 'fmContentType', weight: 1 }, - ...(isLocaleEnabled && data.sameLocale ? [{ name: 'fmLocale.locale', weight: 1 }] : []) - ], + keys: fuseKeys, findAllMatches: true, threshold: 0 }; @@ -61,13 +64,14 @@ export class FieldsListener extends BaseListener { ); const fuseIndex = Fuse.parseIndex(pagesIndex); const fuse = new Fuse(pages || [], fuseOptions, fuseIndex); + + const andExpression: Fuse.Expression[] = [{ fmContentType: data.type ?? '' }]; + if (isLocaleEnabled && activeLocale?.locale && data.sameLocale) { + andExpression.push({ 'fmLocale.locale': activeLocale.locale }); + } + const results = fuse.search({ - $and: [ - { fmContentType: data.type ?? '' }, - ...(isLocaleEnabled && activeLocale?.locale && data.sameLocale - ? [{ 'fmLocale.locale': activeLocale.locale }] - : []) - ] + $and: andExpression }); const pageResults = results.map((page) => page.item);