From 12afa75bb798ee113f54bdef3f7ecb9cecc5c2cd Mon Sep 17 00:00:00 2001 From: Mara Date: Sun, 3 Sep 2023 19:52:29 +0200 Subject: [PATCH] refactor(files): allow optional chaining --- src/GitHub/files.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/GitHub/files.ts b/src/GitHub/files.ts index 582183d5..8d0f3e30 100644 --- a/src/GitHub/files.ts +++ b/src/GitHub/files.ts @@ -150,7 +150,7 @@ export class FilesManagement extends Publisher { * In case there's a frontmatter configuration, pass along * `filename` so we can later use that to convert wikilinks. */ - if (frontmatter && frontmatter[this.settings.upload.frontmatterTitle.key]) { + if (frontmatter?.[this.settings.upload.frontmatterTitle.key]) { frontmatterDestinationFilePath = frontmatter[this.settings.upload.frontmatterTitle.key]; if (altText === imageLink.basename) { altText = frontmatterDestinationFilePath; @@ -445,7 +445,7 @@ export class FilesManagement extends Publisher { frontmatterSettings: FrontmatterConvert ): Promise { for (const field of this.settings.embed.keySendFile) { - if (frontmatterSourceFile&&frontmatterSourceFile[field] != undefined) { + if (frontmatterSourceFile?.[field]) { const imageLinkPath = frontmatterSourceFile[field] instanceof Array ? frontmatterSourceFile[field] : [frontmatterSourceFile[field]]; for (const path of imageLinkPath) { const pathToCheck = path.replace(/\[{2}(.*)\]{2}/, "$1"); @@ -461,12 +461,13 @@ export class FilesManagement extends Publisher { } } } + embedFiles = [...new Set(embedFiles)].filter((x) => x != null); // @ts-ignore if (this.plugin.app.plugins.enabledPlugins.has("dataview")) { const dvApi = getAPI(); - if (!dvApi) return [...new Set(embedFiles)].filter((x) => x != null); + if (!dvApi) return embedFiles; const dataviewMetadata = dvApi.page(file.path); - if (!dataviewMetadata) return [...new Set(embedFiles)].filter((x) => x != null); + if (!dataviewMetadata) return embedFiles; for (const field of this.settings.embed.keySendFile) { const fieldValue = dataviewMetadata[field]; if (fieldValue != undefined) {