From 414e9806471c79a9e4dc40a0c92162ddc11a79f9 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Sat, 30 Sep 2023 10:49:41 +0200 Subject: [PATCH 1/2] Update pin icon --- src/dashboardWebView/components/Icons/PinIcon.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dashboardWebView/components/Icons/PinIcon.tsx b/src/dashboardWebView/components/Icons/PinIcon.tsx index 438bbeb4..ae20db7d 100644 --- a/src/dashboardWebView/components/Icons/PinIcon.tsx +++ b/src/dashboardWebView/components/Icons/PinIcon.tsx @@ -8,6 +8,6 @@ export const PinIcon: React.FunctionComponent = ({ className }: React.PropsWithChildren) => { return ( - + ); }; \ No newline at end of file From 90bfa87995f57f927b0b56e5942a675aeba3343a Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Sat, 30 Sep 2023 11:25:06 +0200 Subject: [PATCH 2/2] #678 - Check field type of `tags` fields for tags rendering on item cards --- CHANGELOG.md | 1 + .../components/Contents/Item.tsx | 3 +- src/services/PagesParser.ts | 39 ++++++++++++------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccf8877f..23a1993a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ - [#664](https://github.com/estruyf/vscode-front-matter/issues/664): Fix for parsing draft status in Hexo and Jekyll - [#665](https://github.com/estruyf/vscode-front-matter/issues/665): Added `dev` parameter to Nuxt script - [#668](https://github.com/estruyf/vscode-front-matter/issues/668): Reset pagination on media search +- [#678](https://github.com/estruyf/vscode-front-matter/issues/678): Check field type of `tags` fields for tags rendering on item cards ## [9.2.0] - 2023-09-11 diff --git a/src/dashboardWebView/components/Contents/Item.tsx b/src/dashboardWebView/components/Contents/Item.tsx index 5081bf38..84240b60 100644 --- a/src/dashboardWebView/components/Contents/Item.tsx +++ b/src/dashboardWebView/components/Contents/Item.tsx @@ -62,7 +62,8 @@ export const Item: React.FunctionComponent = ({ if (typeof tagsValue === 'string') { return [tagsValue]; } else if (Array.isArray(tagsValue)) { - return tagsValue; + const items = tagsValue.map(t => typeof t === 'string' ? t : undefined); + return items.filter(t => t !== undefined) as string[]; } return []; diff --git a/src/services/PagesParser.ts b/src/services/PagesParser.ts index 329554f3..2d421c54 100644 --- a/src/services/PagesParser.ts +++ b/src/services/PagesParser.ts @@ -238,21 +238,32 @@ export class PagesParser { previewFieldParents = ['preview']; } } + // Retrieve the tags from the artilce + let tagParents = ContentType.findFieldsByTypeDeep(contentType.fields, 'tags'); + if (tagParents.length > 0) { + const firstField = tagParents[0]; + if (firstField.length > 0) { + const tagsValue = ContentType.getFieldValue( + article.data, + firstField.map((f) => f.name) + ); + page.fmTags = typeof tagsValue === 'string' ? tagsValue.split(',') : tagsValue; + } + } - let tagParents = ContentType.findFieldByType(contentType.fields, 'tags'); - const tagsValue = ContentType.getFieldValue( - article.data, - tagParents.length !== 0 ? tagParents : ['tags'] - ); - page.fmTags = typeof tagsValue === 'string' ? tagsValue.split(',') : tagsValue; - - let categoryParents = ContentType.findFieldByType(contentType.fields, 'categories'); - const categoriesValue = ContentType.getFieldValue( - article.data, - categoryParents.length !== 0 ? categoryParents : ['categories'] - ); - page.fmCategories = - typeof categoriesValue === 'string' ? categoriesValue.split(',') : categoriesValue; + // Retrieve the categories from the artilce + let categoryParents = ContentType.findFieldsByTypeDeep(contentType.fields, 'categories'); + if (categoryParents.length > 0) { + const firstField = categoryParents[0]; + if (firstField.length > 0) { + const categoriesValue = ContentType.getFieldValue( + article.data, + firstField.map((f) => f.name) + ); + page.fmCategories = + typeof categoriesValue === 'string' ? categoriesValue.split(',') : categoriesValue; + } + } // Check if parent fields were retrieved, if not there was no image present if (previewFieldParents.length > 0) {