Skip to content

Commit

Permalink
Merge branch 'beta' of github.com:estruyf/vscode-front-matter into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Nov 6, 2024
2 parents 2c4dbeb + 17164df commit 5f7f847
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"l10n": "./l10n",
"categories": [
"AI",
"Other"
"Visualization"
],
"keywords": [
"Front Matter",
Expand Down
24 changes: 14 additions & 10 deletions src/listeners/panel/FieldsListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Page> = {
keys: [
{ name: 'fmContentType', weight: 1 },
...(isLocaleEnabled && data.sameLocale ? [{ name: 'fmLocale.locale', weight: 1 }] : [])
],
keys: fuseKeys,
findAllMatches: true,
threshold: 0
};
Expand All @@ -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);

Expand Down

0 comments on commit 5f7f847

Please sign in to comment.