Skip to content

Commit 9daa550

Browse files
committed
Refactor attachment location handling and update version to 1.1.1
1 parent 0bf58d2 commit 9daa550

File tree

6 files changed

+15
-28
lines changed

6 files changed

+15
-28
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Perfect for publishing to static sites like [GitHub Pages](https://pages.github.
2727
- **Preservation** - Keep your original notes unchanged in your vault
2828
- **Customizable Paths** - Configure target paths for your uploaded images
2929
- **Optional In-Place Replacement** - Option to update original files directly if preferred
30+
- **Flexible Attachment Locations** – Choose where attachments are saved:
31+
- Vault folder: Adds the attachment to the root of your vault.
32+
- In the folder specified below: Adds the attachment to a specified folder.
33+
- Same folder as current file: Adds the attachment to the same folder as the note you added it to.
34+
- In subfolder under current folder: Adds attachments to a specified folder next to the note you added the attachment to. If it doesn't exist, Obsidian creates it when you add an attachment.
3035

3136
## 🔍 Usage
3237

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"authorUrl": "https://atbug.com",
77
"isDesktopOnly": true,
88
"minAppVersion": "0.11.0",
9-
"version": "1.1.0"
9+
"version": "1.1.1"
1010
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-image-upload-toolkit",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "",
55
"author": "addozhang",
66
"main": "main.js",

src/publish.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export interface PublishSettings {
2222
imageAltText: boolean;
2323
replaceOriginalDoc: boolean;
2424
ignoreProperties: boolean;
25-
attachmentLocation: string;
2625
imageStore: string;
2726
showProgressModal: boolean; // New setting to control progress modal display
2827
//Imgur Anonymous setting
@@ -40,7 +39,6 @@ const DEFAULT_SETTINGS: PublishSettings = {
4039
imageAltText: true,
4140
replaceOriginalDoc: false,
4241
ignoreProperties: true,
43-
attachmentLocation: ".",
4442
imageStore: ImageStore.IMGUR.id,
4543
showProgressModal: true, // Default to showing the modal
4644
imgurAnonymousSetting: {clientId: IMGUR_PLUGIN_CLIENT_ID},

src/ui/publishSettingTab.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {App, Notice, PluginSettingTab, Setting} from "obsidian";
1+
import {App, PluginSettingTab, Setting} from "obsidian";
22
import ObsidianPublish from "../publish";
33
import ImageStore from "../imageStore";
44
import {AliYunRegionList} from "../uploader/oss/common";
@@ -21,24 +21,6 @@ export default class PublishSettingTab extends PluginSettingTab {
2121
const imageStoreTypeDiv = containerEl.createDiv();
2222
this.imageStoreDiv = containerEl.createDiv();
2323

24-
// Attachment location
25-
new Setting(imageStoreTypeDiv)
26-
.setName("Attachment location")
27-
.setDesc("The location storing images which will upload images from.")
28-
.addText(text =>
29-
text
30-
.setPlaceholder("Enter folder name")
31-
.setValue(this.plugin.settings.attachmentLocation)
32-
.onChange(async (value) => {
33-
if ((await this.app.vault.getAbstractFileByPath(value)) == null) {
34-
new Notice(`Attachment location "${value}" not exist!`)
35-
return
36-
}
37-
this.plugin.settings.attachmentLocation = value;
38-
39-
})
40-
);
41-
4224
new Setting(imageStoreTypeDiv)
4325
.setName("Use image name as Alt Text")
4426
.setDesc("Whether to use image name as Alt Text with '-' and '_' replaced with space.")

src/uploader/imageTagProcessor.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {App, Editor, FileSystemAdapter, MarkdownView, normalizePath, Notice, setIcon} from "obsidian";
1+
import {App, Editor, FileSystemAdapter, MarkdownView, normalizePath, Notice} from "obsidian";
22
import path from "path";
33
import ImageUploader from "./imageUploader";
44
import {PublishSettings} from "../publish";
@@ -24,12 +24,12 @@ interface ResolvedImagePath {
2424
export const ACTION_PUBLISH: string = "PUBLISH";
2525

2626
export default class ImageTagProcessor {
27-
private app: App;
27+
private readonly app: App;
2828
private readonly imageUploader: ImageUploader;
2929
private settings: PublishSettings;
3030
private adapter: FileSystemAdapter;
3131
private progressModal: UploadProgressModal | null = null;
32-
private useModal: boolean = true; // Set to true to use modal, false to use status bar
32+
private readonly useModal: boolean = true; // Set to true to use modal, false to use status bar
3333

3434
constructor(app: App, settings: PublishSettings, imageUploader: ImageUploader, useModal: boolean = true) {
3535
this.app = app;
@@ -186,8 +186,10 @@ export default class ImageTagProcessor {
186186
imageName;
187187

188188
if(imageName.indexOf('/') < 0) {
189-
pathName = path.join(this.app.vault.config.attachmentFolderPath, pathName);
190-
if (this.app.vault.config.attachmentFolderPath.startsWith('.')) {
189+
// @ts-ignore: config is not defined in vault api, but available
190+
const attachmentFolderPath = this.app.vault.config.attachmentFolderPath;
191+
pathName = path.join(attachmentFolderPath, pathName);
192+
if (attachmentFolderPath.startsWith('.')) {
191193
pathName = './' + pathName;
192194
}
193195
}

0 commit comments

Comments
 (0)