From c51f7b3a6df4f586098543fd740434a44edf3267 Mon Sep 17 00:00:00 2001 From: Mara Date: Tue, 14 Jun 2022 18:04:13 +0200 Subject: [PATCH] fix(img): fix image path error Close #7 --- mkdocsPublisher/githubInteraction/getFiles.ts | 18 ++++++++++++------ mkdocsPublisher/settings.ts | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mkdocsPublisher/githubInteraction/getFiles.ts b/mkdocsPublisher/githubInteraction/getFiles.ts index 91c3d6ee..3f5c0b82 100644 --- a/mkdocsPublisher/githubInteraction/getFiles.ts +++ b/mkdocsPublisher/githubInteraction/getFiles.ts @@ -46,6 +46,17 @@ export class GetFiles { return shared_File; } + createDefaultImagePath(file: TFile) { + let fileDefaultPath = file.path; + const fileName = file.name; + if (this.settings.defaultImageFolder.length > 0) { + fileDefaultPath = this.settings.defaultImageFolder + "/" + fileName; + } else if (this.settings.folderDefaultName.length > 0) { + fileDefaultPath = this.settings.folderDefaultName + "/" + fileName; + } + return fileDefaultPath; + } + getAllFileWithPath() { const files = this.vault.getFiles(); const allFileWithPath = []; @@ -53,12 +64,7 @@ export class GetFiles { for (const file of files) { const fileExtension = file.extension; if (fileExtension.match(/(png|jpe?g|svg|bmp|gif)$/i)) { - const filepath = - this.settings.defaultImageFolder.length > 0 - ? this.settings.defaultImageFolder + "/" + file.path - : this.settings.folderDefaultName.length > 0 - ? this.settings.folderDefaultName + "/" + file.path - : file.path; + const filepath = this.createDefaultImagePath(file); allFileWithPath.push(filepath); } else if (file.extension == "md") { const frontMatter = this.metadataCache.getCache( diff --git a/mkdocsPublisher/settings.ts b/mkdocsPublisher/settings.ts index d4576ebf..64ed4c83 100644 --- a/mkdocsPublisher/settings.ts +++ b/mkdocsPublisher/settings.ts @@ -189,7 +189,7 @@ export class MkdocsSettingsTab extends PluginSettingTab { text .setPlaceholder('docs/images') .setValue(this.plugin.settings.defaultImageFolder) - .onChange(async(value)=>{ + .onChange(async(value) => { this.plugin.settings.defaultImageFolder = value.replace(/\/$/, ''); await this.plugin.saveSettings(); });