Last active
December 31, 2024 18:06
-
-
Save brokosz/000e1fb70919781dda151294039317ac to your computer and use it in GitHub Desktop.
Obsidian Popclip Extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # PopClip - Obsidian daily note | |
| name: Obsidian Daily | |
| icon: iconify:majesticons:note-text-plus-line | |
| options: | |
| - identifier: vault | |
| label: Vault Name | |
| type: string | |
| capture html: true | |
| javascript: | | |
| const vaultName = encodeURIComponent(popclip.options.vault); | |
| const todayISO = new Date().toISOString().split('T')[0]; | |
| // Function to sanitize content minimally | |
| const sanitize = (input) => | |
| input.replace(/[<>:"/\\|?*\x00-\x1F]/g, '').slice(0, 100); // Remove invalid filesystem characters | |
| // Function to generate a better title | |
| const generateTitle = (input) => { | |
| let title = input.split('\n').find((line) => line.trim()); // First non-empty line | |
| return sanitize(title.replace(/[#*_`~>]/g, '').trim()); // Remove Markdown and trim | |
| }; | |
| const content = popclip.input.markdown; // Original Markdown content | |
| const link = popclip.context.browserUrl | |
| ? `\n[${popclip.context.browserTitle}](${popclip.context.browserUrl})` | |
| : ''; | |
| const clipping = `${content}${link}\n#clipped`; // Link placed after content | |
| const heading = encodeURIComponent(todayISO); | |
| // Append to daily note | |
| popclip.openUrl( | |
| `obsidian://advanced-uri?vault=${vaultName}&daily&data=${encodeURIComponent(clipping)}&mode=append&heading=${heading}` | |
| ); | |
| # PopClip - Obsidian new note | |
| name: Obsidian | |
| icon: iconify:simple-icons:obsidian | |
| options: | |
| - identifier: vault | |
| label: Vault Name | |
| type: string | |
| capture html: true | |
| javascript: | | |
| const vaultName = encodeURIComponent(popclip.options.vault); | |
| const sanitize = (input) => | |
| input.replace(/[<>:"/\\|?*\x00-\x1F]/g, '').slice(0, 100); // Remove invalid filesystem characters | |
| const generateTitle = (input) => { | |
| let title = input.split('\n').find((line) => line.trim()); | |
| return sanitize(title.replace(/[#*_`~>]/g, '').trim()); | |
| }; | |
| const content = popclip.input.markdown; // Retain original Markdown content | |
| const title = popclip.context.browserTitle || generateTitle(content); | |
| const safeTitle = sanitize(title); // Safe filename | |
| const link = popclip.context.browserUrl | |
| ? `\n[${popclip.context.browserTitle}](${popclip.context.browserUrl})` | |
| : ''; | |
| const data = `${content}${link}\n#clipped`; // Link placed after content | |
| popclip.openUrl( | |
| `obsidian://advanced-uri?vault=${vaultName}&filepath=${encodeURIComponent(safeTitle)}.md&data=${encodeURIComponent(data)}` | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment