shunnna (39.♡.222.244)
2025년 2월 13일 PM 01:33


const prefix = "Insert_local_url";
function Insert_local_url() {
log("START");
const clipText = electron.clipboard.readText().trim();
if (!clipText) {
log("clipboard is empty or doesn’t content a text");
return;
}
if (!isLocalPath(clipText)) {
log("The clipboard doesn’t content a local path.");
return;
}
log(`clipText: ${clipText}`);
// edit this line to remove or move the <% tp.file.cursor(1) %>
// set it in this script instead of the template to prevent failure to jump to cursor
const url = `[${clipText}](<file:///${clipText}>)<% tp.file.cursor(1) %>`;
log("clipText can be successfully inserted");
return url;
}
module.exports = Insert_local_url;
function log(msg) {
console.log(`[${prefix}] ${msg}`);
}
// return boolean if path is a local path
function isLocalPath(path) {
// Expression régulière pour les chemins de fichiers Windows
const windowsPathPattern =
/^[a-z]:\\(?:[^\\\/*:?<>|"\r\n]+\\)*[^\\\/*:?<>|"\r\n]*$/im;
// Expression régulière pour les chemins de fichiers Unix (Linux/Mac)
const unixPathPattern = /^(\/[^\/\0]+)+\/?$/im;
return windowsPathPattern.test(path) || unixPathPattern.test(path);
}
<% tp.user.Insert_local_url() -%>
<%*
tp.hooks.on_all_templates_executed(async () => {
app.commands.executeCommandById("templater-obsidian:jump-to-next-cursor-location");
});
-%>
인용:
[1] How to link a local file in Obsidian? - Help https://forum.obsidian.md/t/how-to-link-a-local-file-in-obsidian/5815
[2] marcjulianschwarz/obsidian-file-link: A plugin for the note ... - GitHub https://github.com/marcjulianschwarz/obsidian-file-link
[3] Installation - Templater - SilentVoid https://silentvoid13.github.io/Templater/installation.html
[4] How to create a template in Obsidian (Beginner's Tutorial) - YouTube https://www.youtube.com/watch?v=91H_0ii4S-A
[5] Here is a snippet to insert link to a local file of folder (outside vault) https://forum.obsidian.md/t/here-is-a-snippet-to-insert-link-to-a-local-file-of-folder-outside-vault/91625
[6] Obsidian - Add links for folders, files and application. - YouTube https://www.youtube.com/watch?v=bcZ57-D6TsY
[7] SilentVoid13/Templater: A template plugin for obsidian - GitHub https://github.com/SilentVoid13/Templater
[8] How to setup Obsidian for projects using Templater with simple ... https://forum.obsidian.md/t/how-to-setup-obsidian-for-projects-using-templater-with-simple-aggregation-will-determine-if-obsidian-is-ease-enough-to-use/60050
[9] Link to Local File : r/ObsidianMD - Reddit https://www.reddit.com/r/ObsidianMD/comments/13vqlpg/link_to_local_file/
[10] Linking to external files & folders - Obsidian Forum https://forum.obsidian.md/t/linking-to-external-files-folders/70121
[11] Help with Templater Plugin - Obsidian Forum https://forum.obsidian.md/t/help-with-templater-plugin/9768
[12] An easier process for linking to external file manager - Obsidian Forum https://forum.obsidian.md/t/an-easier-process-for-linking-to-external-file-manager/39608
[13] Using the Obsidian Templater Plugin - YouTube https://www.youtube.com/watch?v=5j9fAvJCaig
[14] How to create a link to local file on MacOS? - Help - Obsidian Forum https://forum.obsidian.md/t/how-to-create-a-link-to-local-file-on-macos/86263
[15] Using Templater in Obsidian - Curtis McHale https://curtismchale.ca/2021/07/05/using-templater-in-obsidian/
[16] Link to a file outside the vault on a - Help - Obsidian Forum https://forum.obsidian.md/t/link-to-a-file-outside-the-vault-on-a/80389
[17] How to link a local file in Obsidian? - #19 by fierce_ninja - Help https://forum.obsidian.md/t/how-to-link-a-local-file-in-obsidian/5815/19
[18] Linking to file on local hard drive - Basement - Obsidian Forum https://forum.obsidian.md/t/linking-to-file-on-local-hard-drive/12043
[19] Local links in Obsidian's Markdown? - Help https://forum.obsidian.md/t/local-links-in-obsidians-markdown/12290
[20] Insert metadata as a link to a file/folder path - Help - Obsidian Forum https://forum.obsidian.md/t/insert-metadata-as-a-link-to-a-file-folder-path/89789
[21] File operations into a file (drag and drop, cut/copy/paste, file links) https://forum.obsidian.md/t/file-operations-into-a-file-drag-and-drop-cut-copy-paste-file-links/6607
[22] Allow to open local file - Page 2 - Obsidian Forum https://forum.obsidian.md/t/allow-to-open-local-file/156?page=2
[23] Local file link doesn't work except on home/root partition (MX linux) https://discuss.logseq.com/t/local-file-link-doesnt-work-except-on-home-root-partition-mx-linux/22990
[24] please help me with templates/daily notes/tasks 101 : r/ObsidianMD https://www.reddit.com/r/ObsidianMD/comments/16kkhf2/please_help_me_with_templatesdaily_notestasks_101/
[25] If you install and enable templater should you then disable the core ... https://forum.obsidian.md/t/if-you-install-and-enable-templater-should-you-then-disable-the-core-templates-plugin/67453
[26] How to Use Templater in Obsidian - YouTube https://www.youtube.com/watch?v=QpJbeP8f55A
댓글 (0)
- 아직 댓글이 없습니다. 첫 댓글을 작성해보세요!
댓글을 작성하려면 이 필요합니다.