Skip to content

Commit 45cdcce

Browse files
committed
other: Obsidian settings change
1 parent 74464d6 commit 45cdcce

File tree

6 files changed

+746
-69
lines changed

6 files changed

+746
-69
lines changed

.obsidian/appearance.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"accentColor": "",
33
"baseFontSize": 23,
4-
"cssTheme": "Shimmering Focus"
4+
"cssTheme": "Dracula for Obsidian",
5+
"baseFontSizeAction": true
56
}

.obsidian/plugins/image_collector/main.js

Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,11 @@ __export(main_exports, {
2828
});
2929
module.exports = __toCommonJS(main_exports);
3030
var import_obsidian = require("obsidian");
31-
var DEFAULT_SETTINGS = {
32-
imageFolderPath: "zAttachments"
33-
// Default folder
34-
};
35-
var ImageCollectorSettingTab = class extends import_obsidian.PluginSettingTab {
36-
constructor(app, plugin) {
37-
super(app, plugin);
38-
this.plugin = plugin;
39-
}
40-
display() {
41-
const { containerEl } = this;
42-
containerEl.empty();
43-
containerEl.createEl("h2", { text: "Image Collector Settings" });
44-
new import_obsidian.Setting(containerEl).setName("Image Folder Path").setDesc("The folder where images are stored").addText((text) => text.setPlaceholder("Enter your image folder path").setValue(this.plugin.settings.imageFolderPath).onChange(async (value) => {
45-
this.plugin.settings.imageFolderPath = value;
46-
await this.plugin.saveSettings();
47-
}));
48-
}
49-
};
5031
var ImageCollectorPlugin = class extends import_obsidian.Plugin {
5132
async onload() {
52-
await this.loadSettings();
5333
this.addCommand({
54-
id: "export-markdown-images-command",
55-
name: "Export Markdown Images",
34+
id: "export-markdown-images",
35+
name: "Export markdown images",
5636
callback: () => {
5737
const activeFile = this.app.workspace.getActiveFile();
5838
if (activeFile && activeFile instanceof import_obsidian.TFile && activeFile.extension === "md") {
@@ -62,47 +42,37 @@ var ImageCollectorPlugin = class extends import_obsidian.Plugin {
6242
}
6343
}
6444
});
65-
this.addSettingTab(new ImageCollectorSettingTab(this.app, this));
6645
this.registerEvent(this.app.workspace.on("file-menu", (menu, file) => {
6746
if (file instanceof import_obsidian.TFile && file.extension === "md") {
6847
menu.addItem((item) => {
69-
item.setTitle("Export Images with My Plugin").setIcon("document-export").onClick(() => {
48+
item.setTitle("Export images").setIcon("document-export").onClick(() => {
7049
this.exportMarkdownImages(file);
7150
});
7251
});
7352
}
7453
}));
7554
}
76-
async loadSettings() {
77-
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
78-
}
79-
async saveSettings() {
80-
await this.saveData(this.settings);
81-
}
8255
async exportMarkdownImages(file) {
83-
const activeFile = this.app.workspace.getActiveFile();
84-
if (!activeFile || activeFile.extension !== "md") {
85-
new import_obsidian.Notice("No active markdown file.");
86-
return;
87-
}
88-
const fileContent = await this.app.vault.read(activeFile);
89-
const imageRegex = /!\[\[?(.*?)\]?\]/g;
56+
const fileContent = await this.app.vault.read(file);
57+
const imageRegex = /!\[\[(.*?)\]\]|!\[(?:.*?)\]\((.*?)\s*(".*?")?\)/g;
9058
let match;
9159
const images = [];
9260
while ((match = imageRegex.exec(fileContent)) !== null) {
93-
const imagePath = match[1].includes("|") ? match[1].split("|")[0] : match[1];
94-
images.push(imagePath);
61+
let imagePath = match[1] || match[2];
62+
if (imagePath) {
63+
imagePath = decodeURIComponent(imagePath.trim());
64+
images.push(imagePath);
65+
}
9566
}
9667
if (images.length === 0) {
9768
new import_obsidian.Notice("No images found in the markdown file.");
9869
return;
9970
}
100-
const targetFolderName = `${activeFile.basename} images`;
71+
const targetFolderName = `${file.basename} images`;
10172
await this.app.vault.createFolder(targetFolderName).catch(() => {
10273
});
10374
for (const imagePath of images) {
104-
const resolvedImagePath = this.resolveImagePath(activeFile, imagePath);
105-
const imageFile = this.app.vault.getAbstractFileByPath(resolvedImagePath);
75+
const imageFile = this.app.metadataCache.getFirstLinkpathDest(imagePath, file.path);
10676
if (imageFile instanceof import_obsidian.TFile) {
10777
try {
10878
const imageContent = await this.app.vault.readBinary(imageFile);
@@ -114,25 +84,9 @@ var ImageCollectorPlugin = class extends import_obsidian.Plugin {
11484
console.error(`Failed to export image ${imageFile.name}:`, error);
11585
}
11686
} else {
117-
new import_obsidian.Notice(`Image not found: ${resolvedImagePath}`);
118-
console.error(`Image not found: ${resolvedImagePath}`);
119-
}
120-
}
121-
}
122-
resolveImagePath(activeFile, imagePath) {
123-
let normalizedPath = imagePath.replace(/\[\[|\]\]/g, "");
124-
let basePath = this.settings.imageFolderPath;
125-
if (normalizedPath.startsWith("/") || normalizedPath.startsWith(`${basePath}/`)) {
126-
return normalizedPath;
127-
}
128-
if (activeFile.parent) {
129-
const folderPath = activeFile.parent.path;
130-
const fullPath = `${folderPath}/${normalizedPath}`;
131-
const fileExists = this.app.vault.getAbstractFileByPath(fullPath);
132-
if (fileExists) {
133-
return fullPath;
87+
new import_obsidian.Notice(`Image not found: ${imagePath}`);
88+
console.error(`Image not found: ${imagePath}`);
13489
}
13590
}
136-
return `${basePath}/${normalizedPath}`;
13791
}
13892
};
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"id": "image_collector",
33
"name": "Image Collector",
4-
"version": "1.0.0",
4+
"version": "1.0.2",
55
"minAppVersion": "0.15.0",
66
"description": "Collects all of the images in an Obsidian (markdown) note and exports them to a folder called 'file_name images'.",
77
"author": "tdaykin",
8-
"authorUrl": "[email protected]",
9-
"fundingUrl": "[email protected]",
8+
"authorUrl": "tdaykin.github.io",
109
"isDesktopOnly": false
1110
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "Dracula for Obsidian",
3+
"version": "0.0.0",
4+
"minAppVersion": "0.16.0",
5+
"author": "jarodise"
6+
}

0 commit comments

Comments
 (0)