Skip to content

Commit

Permalink
fix(img): fix image path error
Browse files Browse the repository at this point in the history
Close #7
  • Loading branch information
Mara-Li committed Jun 14, 2022
1 parent 2beb0fa commit c51f7b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions mkdocsPublisher/githubInteraction/getFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,25 @@ 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 = [];
const shareKey = this.settings.shareKey;
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(
Expand Down
2 changes: 1 addition & 1 deletion mkdocsPublisher/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit c51f7b3

Please sign in to comment.