Skip to content

Commit 7d75481

Browse files
committed
code review fix
1 parent 48ca792 commit 7d75481

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023
3+
Copyright (c) 2024 Por Chainarong Tangsurakit
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Quick Share Note to Gist (Plugin)
1+
# Quick Share Note to gist (Plugin)
22

3-
**Quick Share Note to Gist** is an Obsidian plugin. ✨ It quickly publish your notes to GitHub Gist (SECRET, but shareable) 🚀 and also UPLOAD IMAGES to ImgUr! 🌈
3+
**Quick Share Note to gist** is an Obsidian plugin. ✨ It quickly publish your notes to GitHub gist (SECRET, but shareable) 🚀 and also UPLOAD IMAGES to ImgUr! 🌈
44

55
## DEMO
66
![Demo of Plugin](./docs/DEMO.gif)
@@ -21,13 +21,13 @@ After enabling the plugin, go to the plugin settings to configure the following
2121
## Usage
2222

2323
1. Open the note you want to publish in Obsidian.
24-
2. Use the command palette (`Ctrl+P` or `Cmd+P`) and select `Publish Note to GitHub Gist`.
25-
3. The plugin will upload the note and any images to GitHub Gist and Imgur, respectively.
26-
4. A notification will appear with the Gist URL, which will also be copied to your clipboard.
24+
2. Use the command palette (`Ctrl+P` or `Cmd+P`) and select `Publish note to GitHub gist`.
25+
3. The plugin will upload the note and any images to GitHub gist and Imgur, respectively.
26+
4. A notification will appear with the gist URL, which will also be copied to your clipboard.
2727

2828
## Features
2929

30-
- Publish notes to GitHub Gist.
30+
- Publish notes to GitHub gist.
3131
- Upload images to Imgur and replace links in the gist note.
3232
- Option to include or exclude frontmatter in the published note.
3333
- Copy gist URL into clipboard, and paste in frontmatter field of ur note.

main.ts

+14-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default class QuickShareNotePlugin extends Plugin {
2121

2222
this.addCommand({
2323
id: 'publish-note-to-gist',
24-
name: 'Publish Note to GitHub Gist',
24+
name: 'Publish note to GitHub gist',
2525
callback: () => this.publishNoteToGist(),
2626
});
2727
}
@@ -33,7 +33,7 @@ export default class QuickShareNotePlugin extends Plugin {
3333
return;
3434
}
3535

36-
const notice = new Notice(`Uploading Notes and Images: ${activeFile.name}...`, 0); // Include file name
36+
const notice = new Notice(`Uploading notes and images: ${activeFile.name}...`, 0); // Include file name
3737
let fileContent = await this.app.vault.read(activeFile);
3838
let updatedContent = await this.uploadImagesAndReplaceLinks(fileContent);
3939

@@ -69,7 +69,7 @@ export default class QuickShareNotePlugin extends Plugin {
6969
this.copyLinkToClipboard(gistUrl);
7070
await this.updateFrontmatter(activeFile, gistUrl);
7171
notice.hide();
72-
new Notice('Note published to GitHub Gist');
72+
new Notice('Note published to GitHub gist');
7373
}
7474

7575
async addHeaderToContent(file: TFile) {
@@ -104,8 +104,12 @@ export default class QuickShareNotePlugin extends Plugin {
104104
const notePath = activeFile ? activeFile.path.replace(/[^/]+$/, '') : '';
105105
let match;
106106
while ((match = imageRegex.exec(content)) !== null) {
107-
const imagePath = `${notePath}/attachments/${match[1]}`;
108-
const imageData = await this.app.vault.adapter.readBinary(imagePath);
107+
// const imagePath = `${notePath}/attachments/${match[1]}`;
108+
const attachFile = this.app.metadataCache.getFirstLinkpathDest(match[1], notePath);
109+
if (attachFile == null) {
110+
continue;
111+
}
112+
const imageData = await this.app.vault.adapter.readBinary(attachFile.path);
109113
const imageUrl = await this.uploadImageToImgur(imageData);
110114
content = content.replace(match[0], `![Uploaded Image](${imageUrl})`);
111115
}
@@ -127,9 +131,9 @@ export default class QuickShareNotePlugin extends Plugin {
127131

128132
copyLinkToClipboard(link: string) {
129133
navigator.clipboard.writeText(link).then(() => {
130-
new Notice('Gist URL copied to clipboard');
134+
new Notice('gist URL copied to clipboard');
131135
}, (err) => {
132-
new Notice('Failed to copy Gist URL to clipboard');
136+
new Notice('Failed to copy gist URL to clipboard');
133137
});
134138
}
135139

@@ -155,10 +159,8 @@ class QuickShareNoteSettingTab extends PluginSettingTab {
155159

156160
containerEl.empty();
157161

158-
containerEl.createEl('h2', { text: 'Quick Share Note to Gist Plugin Settings' });
159-
160162
new Setting(containerEl)
161-
.setName('GitHub Token')
163+
.setName('GitHub token')
162164
.setDesc('Enter your GitHub token')
163165
.addText(text => text
164166
.setPlaceholder('Enter your token')
@@ -169,7 +171,7 @@ class QuickShareNoteSettingTab extends PluginSettingTab {
169171
}));
170172

171173
new Setting(containerEl)
172-
.setName('Imgur Client ID')
174+
.setName('Imgur client ID')
173175
.setDesc('Enter your Imgur client ID')
174176
.addText(text => text
175177
.setPlaceholder('Enter your client ID')
@@ -180,7 +182,7 @@ class QuickShareNoteSettingTab extends PluginSettingTab {
180182
}));
181183

182184
new Setting(containerEl) // Add this block
183-
.setName('Show Frontmatter')
185+
.setName('Show frontmatter')
184186
.setDesc('Show frontmatter in published note')
185187
.addToggle(toggle => toggle
186188
.setValue(this.plugin.settings.showFrontmatter)

manifest.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"id": "share-note-img-with-gist",
3-
"name": "Quick Share Note to Gist",
4-
"version": "1.0.10",
2+
"id": "quick-share-note-to-gist",
3+
"name": "Quick Share Note to gist",
4+
"version": "1.0.11",
55
"minAppVersion": "0.15.0",
6-
"description": "Quick publish and share notes to GitHub Gist and its image by upload images to Imgur.",
6+
"description": "Quick share notes to GitHub gist and its image by upload images to Imgur.",
77
"author": "Por Chainarong Tangsurakit",
88
"authorUrl": "https://github.com/chaintng",
99
"isDesktopOnly": false

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "obsidian-sample-plugin",
3-
"version": "1.0.0",
4-
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
2+
"name": "quick-share-note-to-gist",
3+
"version": "1.0.12",
4+
"description": "Quick share notes to GitHub gist and its image by upload images to Imgur (https://github.com/chaintng/quick-share-note-to-gist)",
55
"main": "main.js",
66
"scripts": {
77
"dev": "node esbuild.config.mjs",

0 commit comments

Comments
 (0)