diff --git a/src/main.ts b/src/main.ts index f8c0c92..c3daea3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,6 @@ import {arrayBufferToBase64, Notice, Plugin, requestUrl, TFile} from "obsidian"; import {defaultSettings, JSPSettings, SharedItem} from "./settings"; import {JSPSettingsTab} from "./settings-tab"; -import {basename, extname} from "path"; import {JSPView} from "./view"; export default class JustSharePleasePlugin extends Plugin { @@ -194,7 +193,7 @@ export default class JustSharePleasePlugin extends Plugin { } async deleteFile(item: SharedItem, notice = true): Promise { - let name = basename(item.path, extname(item.path)); + let name = removeExtension(item.path); try { await requestUrl({ url: `${this.settings.url}/share.php?id=${item.id}`, @@ -221,7 +220,7 @@ export default class JustSharePleasePlugin extends Plugin { async copyShareLink(item: SharedItem, notice = true): Promise { await navigator.clipboard.writeText(`${this.settings.url}#${item.id}`); if (notice) - new Notice(`Copied link to ${basename(item.path, extname(item.path))} to clipboard`); + new Notice(`Copied link to ${removeExtension(item.path)} to clipboard`); } async preProcessMarkdown(file: TFile): Promise { @@ -247,7 +246,7 @@ export default class JustSharePleasePlugin extends Plugin { let resolved = this.app.metadataCache.getFirstLinkpathDest(url, file.path).path; let attachment = this.app.vault.getAbstractFileByPath(resolved); let data = arrayBufferToBase64(await this.app.vault.readBinary(attachment as TFile)); - let img = `${alt}`; + let img = `${alt}`; text = text.substring(0, match.index) + img + text.substring(match.index + match[0].length); } catch (e) { console.log(`Error embedding attachment ${url}: ${e}`); @@ -263,4 +262,11 @@ export default class JustSharePleasePlugin extends Plugin { leaf.view.refresh(); } } + +} + +export function removeExtension(file: string): string { + let split = file.split("."); + split.pop(); + return split.join("."); } diff --git a/src/view.ts b/src/view.ts index acf467e..d7711cc 100644 --- a/src/view.ts +++ b/src/view.ts @@ -1,6 +1,5 @@ import {ButtonComponent, ItemView, TFile, WorkspaceLeaf} from "obsidian"; -import {basename, extname} from "path"; -import JustSharePleasePlugin from "./main"; +import JustSharePleasePlugin, {removeExtension} from "./main"; export class JSPView extends ItemView { @@ -20,7 +19,7 @@ export class JSPView extends ItemView { for (let shared of this.plugin.settings.shared) { let file = this.plugin.app.vault.getAbstractFileByPath(shared.path) as TFile; let div = content.createDiv({cls: "just-share-please-shared-item"}); - div.createSpan({cls: "just-share-please-shared-name", text: basename(shared.path, extname(shared.path))}); + div.createSpan({cls: "just-share-please-shared-name", text: removeExtension(shared.path)}); new ButtonComponent(div) .setClass("clickable-icon") .setTooltip("Copy JSP link") diff --git a/test-vault/.obsidian/plugins/just-share-please/data.json b/test-vault/.obsidian/plugins/just-share-please/data.json index 52e5071..e465581 100644 --- a/test-vault/.obsidian/plugins/just-share-please/data.json +++ b/test-vault/.obsidian/plugins/just-share-please/data.json @@ -5,6 +5,11 @@ "id": "234df7b7", "password": "0ef1504bfe83cd9ca812434caa7aacf4", "path": "Cool Test Note.md" + }, + { + "id": "014b266c", + "password": "1c9459d7cdac804f72272c8f6d4a9abc", + "path": "dir/Cool Test Note.md" } ], "stripFrontmatter": true, diff --git a/test-vault/dir/Cool Test Note.md b/test-vault/dir/Cool Test Note.md new file mode 100644 index 0000000..d96d969 --- /dev/null +++ b/test-vault/dir/Cool Test Note.md @@ -0,0 +1,44 @@ +--- +test: yes +--- + +this is the SECOND cool test note!! + +> How are you? + +```js +$.ajax({ + method: "get", + url: id ? `share.php?id=${id}` : "index.md", + success: t => { + main.html(DOMPurify.sanitize(md.render(t))); + + // scroll to anchor + let element = $(window.location.hash); + if (element.length) + $(window).scrollTop(element.offset().top); + }, + error: (r, s, e) => main.html(`

Error loading shared note with id ${id}: ${e}

Home

`) +}); +``` + +cool!! + +blah blah i added and removed this + +The following is $x^2 = 7$, but more complicated! +$$ +x^2 + \sum_{i = 1}^{10000} x^2 \cdot 0 = 7 +$$ + +## Some images + +image! + +![this is an image my friends, and this is my alt text](Obsidian_TtC7w4GA86.png) + +wikilink image! + +![[Pasted image 20230816130420.png]] + +nice \ No newline at end of file