Skip to content

Commit

Permalink
Merge branch 'issue/851' of github.com:wottpal/vscode-front-matter in…
Browse files Browse the repository at this point in the history
…to wottpal-issue/851
  • Loading branch information
estruyf committed Oct 7, 2024
2 parents 73609ca + 39704f3 commit 17860a1
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 167 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,11 @@
"default": "path",
"description": "%setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.contentTypeValue.description%"
},
"sameContentLocale": {
"type": "boolean",
"default": true,
"description": "%setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.sameContentLocale.description%"
},
"when": {
"type": "object",
"description": "%setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.when.description%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
"setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.required.description": "Specify if the field is required",
"setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.contentTypeName.description": "Specify the content type name to filter content for the contentRelationship field",
"setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.contentTypeValue.description": "Specify the value to insert for the contentRelationship field",
"setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.sameContentLocale.description": "Specify if you only want to show the content with the same locale",
"setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.when.description": "Specify the conditions to show the field",
"setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.when.properties.fieldRef.description": "The field ID to use",
"setting.frontMatter.taxonomy.contentTypes.items.properties.fields.items.properties.when.properties.operator.description": "The operator to use",
Expand Down
2 changes: 1 addition & 1 deletion src/listeners/dashboard/PagesListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class PagesListener extends BaseListener {
*/
private static async createSearchIndex(pages: Page[]) {
const pagesIndex = Fuse.createIndex(
['title', 'slug', 'description', 'fmBody', 'type', 'fmContentType'],
['title', 'slug', 'description', 'fmBody', 'type', 'fmContentType', 'fmLocale.locale'],
pages
);
await Extension.getInstance().setState(
Expand Down
26 changes: 20 additions & 6 deletions src/listeners/panel/FieldsListener.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { i18n } from '../../commands';
import { ExtensionState } from '../../constants';
import { Page } from '../../dashboardWebView/models';
import { Extension } from '../../helpers';
Expand Down Expand Up @@ -29,14 +30,28 @@ export class FieldsListener extends BaseListener {
* @param payload
* @returns
*/
private static async searchByType(command: string, requestId?: string, type?: string) {
if (!type || !requestId) {
private static async searchByType(
command: string,
requestId?: string,
data?: { type?: string; sameLocale?: boolean; activePath?: string }
) {
if (!data?.type || !data?.activePath || !requestId) {
return;
}

const activeLocale = await i18n.getLocale(data.activePath);
if (!activeLocale?.locale) {
return;
}

PagesListener.getPagesData(false, async (pages) => {
const fuseOptions: Fuse.IFuseOptions<Page> = {
keys: [{ name: 'fmContentType', weight: 1 }]
keys: [
{ name: 'fmContentType', weight: 1 },
...(data.sameLocale ? [{ name: 'fmLocale.locale', weight: 1 }] : [])
],
findAllMatches: true,
threshold: 0
};

const pagesIndex = await Extension.getInstance().getState<Fuse.FuseIndex<Page>>(
Expand All @@ -47,9 +62,8 @@ export class FieldsListener extends BaseListener {
const fuse = new Fuse(pages || [], fuseOptions, fuseIndex);
const results = fuse.search({
$and: [
{
fmContentType: type
}
{ fmContentType: data.type! },
...(data.sameLocale ? [{ 'fmLocale.locale': activeLocale.locale }] : [])
]
});
const pageResults = results.map((page) => page.item);
Expand Down
1 change: 1 addition & 0 deletions src/models/PanelSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface Field {
// Content relationship
contentTypeName?: string;
contentTypeValue?: 'path' | 'slug';
sameContentLocale?: boolean;

// Custom field
customType?: string;
Expand Down
Loading

0 comments on commit 17860a1

Please sign in to comment.