From 4d4db83b5e3aaa6e1faada53785fa26faad6a033 Mon Sep 17 00:00:00 2001 From: Jamie Steiner Date: Sun, 10 Nov 2024 15:52:07 +0200 Subject: [PATCH] making the frontmatter icons work --- README.md | 93 ++----------------------------------------------- src/main.ts | 12 +++---- src/note.ts | 17 +++++++-- src/settings.ts | 2 +- styles.css | 30 ++++++++-------- 5 files changed, 38 insertions(+), 116 deletions(-) diff --git a/README.md b/README.md index c4a623c..86a1910 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,11 @@ # Share Note -Instantly share / publish a note. Notes are shared with your full theme and should look identical to how they look in your Obsidian vault. +Instantly share / publish a note. Notes are shared in markdown format, and are encrypted by default. This plugin uses Pastebin for storage. When shared, the note is upload to pastebin, and a url is created. Other users who receive the url, can open it in obsidian, and the note will be added to their vault. This allows users a quick and easy way to transport notes from one user to another, as long as both users have this plugin installed. -- 👉 [Install this plugin from the Plugin Store](https://obsidian.md/plugins?id=share-note) -- 📄 [Documentation](https://docs.note.sx/) -- 💬 [Discussion for this plugin](https://forum.obsidian.md/t/42788) -- 🚀 [Request new features / see the roadmap](https://note.sx/roadmap) - -To share a note, choose `Share Note` from the command palette, or click the `⋮` menu in any note and choose `Copy shared link` +To send a note, choose `Send Note` from the command palette, or click the `⋮` menu in any note and choose `Copy shared link` ---- - -## Full theme support - -Uploads using your current theme, along with all your options and custom CSS snippets. - -Supports all Obsidian content types: - -### Images! - - - -### Dataview queries! - -Here's an example inline Dataview query. It will be correctly rendered when sharing: - -``` -The answer is `= 7 + 8`! -``` - -The answer is 15! - -### Callouts! - - - -### Links between notes! - -If your shared note links to another note which is also shared, that link will also function on the shared webpage. - -### Code blocks! - -```javascript -function doYouEven(haveToAsk) { - return 'Of course we can do it!' -} -``` - -### Checkboxes! Tags! - -**Project Manhattan:** #in-progress #behind-schedule - -- [x] Start project -- [x] Procrastinate -- [ ] Finish project - -### Internal links - -Share a table of contents and jump around your document. - ---- - ## Usage Use the `Share Note` command from the Command Palette. You can map it to a hotkey to make things faster. @@ -79,38 +22,6 @@ The content of your note is encrypted by default. What this means is that you ca > 🛈 **Encryption is optional, and can be turned on/off for individual notes, or for all notes, whatever you prefer.** -### 🧑‍💻 How it works - -When you share an encrypted note, you'll get a share link that looks like this: - -https://share.note.sx/4earajc8#PtC3oQDjDQK9VP7fljmQkLBA/rIMb2tbFsGoG44VdFY - -This part is the link to the file: - -https://share.note.sx/4earajc8 - -If you click on it, you'll see a message that says "*Encrypted note*", because you haven't provided the decryption key. - -The decryption key is the second part of the share link after the `#` symbol: - -`#PtC3oQDjDQK9VP7fljmQkLBA/rIMb2tbFsGoG44VdFY` - -When you combine those two things together, the note is able to be decrypted and you can see the content: - -https://share.note.sx/4earajc8#PtC3oQDjDQK9VP7fljmQkLBA/rIMb2tbFsGoG44VdFY - -The decryption key **only** exists inside your vault, and is only known to you and whoever you send the link to. Nobody else can read the content. - -You may optionally share an unencrypted version of a note by using the frontmatter checkbox property `share_unencrypted` = ✅. This note you are currently reading is shared unencrypted. - -If you decide you want to share most notes unencrypted by default, then you can encrypt an individual note by using a frontmatter checkbox called `share_encrypted`. - -## Self-hosting - -If you want to self-host your own server, you can use this repo: - -https://github.com/alangrainger/share-note-self-hosted-backend - ## Troubleshooting See here: [Troubleshooting](https://docs.note.sx/Troubleshooting) diff --git a/src/main.ts b/src/main.ts index c8f8db6..744a526 100644 --- a/src/main.ts +++ b/src/main.ts @@ -43,7 +43,7 @@ export default class SendNotePlugin extends Plugin { if (data.action === "send-note" && data.sendurl && data.filename) { requestUrl(data.sendurl) .then((response) => { - console.log(response.text); + // console.log(response.text); // check if file already exists let newFilename = data.filename; const file = this.app.vault.getAbstractFileByPath(data.filename); @@ -264,12 +264,12 @@ export default class SendNotePlugin extends Plugin { if (linkEl?.innerText !== shareLink) return; // Remove existing elements // valueEl?.querySelectorAll('div.share-note-icons').forEach(el => el.remove()) - if (valueEl && !valueEl.querySelector("div.share-note-icons")) { + if (valueEl && !valueEl.querySelector("div.send-note-icons")) { const iconsEl = document.createElement("div"); - iconsEl.classList.add("share-note-icons"); + iconsEl.classList.add("send-note-icons"); // Re-share note icon const shareIcon = iconsEl.createEl("span"); - shareIcon.title = "Re-share note"; + shareIcon.title = "Re-send note"; setIcon(shareIcon, "upload-cloud"); shareIcon.onclick = () => this.uploadNote(); // Copy to clipboard icon @@ -278,11 +278,11 @@ export default class SendNotePlugin extends Plugin { setIcon(copyIcon, "copy"); copyIcon.onclick = async () => { await navigator.clipboard.writeText(shareLink); - new StatusMessage("📋 Shared link copied to clipboard"); + new StatusMessage("📋 Sending link copied to clipboard"); }; // Delete shared note icon const deleteIcon = iconsEl.createEl("span"); - deleteIcon.title = "Delete shared note"; + deleteIcon.title = "Delete sent note"; setIcon(deleteIcon, "trash-2"); deleteIcon.onclick = () => this.deleteSharedNote(activeFile); valueEl.prepend(iconsEl); diff --git a/src/note.ts b/src/note.ts index 9a21d17..12b7dc4 100644 --- a/src/note.ts +++ b/src/note.ts @@ -107,7 +107,13 @@ export default class Note { let pastebinUserKey = this.plugin.settings.pasteBinUserKey; let expiry = this.plugin.settings.pastebinExpiry; const noteContent = await this.plugin.app.vault.read(this.file); - console.log("noteContent", noteContent); + // console.log("noteContent", noteContent); + await this.plugin.app.fileManager.processFrontMatter(this.file, (frontmatter) => { + if ((frontmatter["send_link"] = true)) { + delete frontmatter["send_link"]; + } + }); + requestUrl({ url: "https://pastebin.com/api/api_post.php", method: "POST", @@ -119,15 +125,20 @@ export default class Note { }&api_paste_expire_date=${expiry}&api_paste_format=text&api_paste_code=${encodeURIComponent(noteContent)}`, }) .then((res) => { - console.log("res", res.text); + // console.log("res", res.text); const urlObj = new URL(res.text); // Get the pathname and split by "/" const pathSegments = urlObj.pathname.split("/"); // The last segment will be the suffix const suffix = pathSegments[pathSegments.length - 1]; const obsidianUrl = `obsidian://send-note?sendurl=https://pastebin.com/raw/${suffix}&filename=${this.file.basename}.md`; - console.log(obsidianUrl); + // console.log(obsidianUrl); navigator.clipboard.writeText(obsidianUrl); + this.plugin.app.fileManager.processFrontMatter(this.file, (frontmatter) => { + if ((frontmatter["send_link"] = true)) { + frontmatter["send_link"] = obsidianUrl; + } + }); }) .catch((err) => { console.log("err", err); diff --git a/src/settings.ts b/src/settings.ts index c59cf12..07d2fb1 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -50,7 +50,7 @@ export const DEFAULT_SETTINGS: SendNoteSettings = { server: "https://api.note.sx", uid: "", apiKey: "", - yamlField: "share", + yamlField: "send", noteWidth: "", theme: "", themeMode: ThemeMode["Same as theme"], diff --git a/styles.css b/styles.css index 372a08f..cfd4ae8 100644 --- a/styles.css +++ b/styles.css @@ -1,24 +1,24 @@ -.share-note-status-error.notice { - background: #c10000; - color: white +.send-note-status-error.notice { + background: #c10000; + color: white; } -.share-note-status-info.notice { - background: hsl(204, 86%, 53%); - color: white +.send-note-status-info.notice { + background: hsl(204, 86%, 53%); + color: white; } -.share-note-status-success.notice { - background: #629762; - color: white +.send-note-status-success.notice { + background: #629762; + color: white; } -.share-note-icons { - display: flex; +.send-note-icons { + display: flex; } -.share-note-icons > span { - display: flex; - margin-left: 6px; - cursor: pointer; +.send-note-icons > span { + display: flex; + margin-left: 6px; + cursor: pointer; }