tech-tips/.obsidian/plugins/obsidian-link-converter/main.js

3 lines
49 KiB
JavaScript
Raw Normal View History

"use strict";var t=require("obsidian");function e(t,e,i,n){return new(i||(i=Promise))((function(o,a){function l(t){try{r(n.next(t))}catch(t){a(t)}}function s(t){try{r(n.throw(t))}catch(t){a(t)}}function r(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(l,s)}r((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const i={mySetting:"default",contextMenu:!0,finalLinkFormat:"not-change",keepMtime:!1};class n extends t.PluginSettingTab{constructor(t,e){super(t,e),this.plugin=e}display(){let{containerEl:e}=this;e.empty(),e.createEl("h2",{text:"Obsidian Link Converter"}),new t.Setting(e).setName("File Context Menu").setDesc("Turn this option off if you don't want single file commands to appear within the file context menu").addToggle((t=>{t.setValue(this.plugin.settings.contextMenu).onChange((t=>{this.plugin.settings.contextMenu=t,this.plugin.saveSettings(),t?this.plugin.app.workspace.on("file-menu",this.plugin.addFileMenuItems):this.plugin.app.workspace.off("file-menu",this.plugin.addFileMenuItems)}))})),new t.Setting(e).setName("Converted Link Format").setDesc("Select the preferred option for the final link format after the conversion. Plugin will use the preferrence where possible").addDropdown((t=>{t.addOption("not-change","Do not change").addOption("relative-path","Relative Path").addOption("absolute-path","Absolute Path").addOption("shortest-path","Shortest Path").setValue(this.plugin.settings.finalLinkFormat).onChange((t=>{this.plugin.settings.finalLinkFormat=t,this.plugin.saveSettings()}))})),new t.Setting(e).setName("Keep mTime (Last Modified Time)").setDesc("Turn on this option if you want plugin to keep the mtime of files same during the link conversion").addToggle((t=>t.setValue(this.plugin.settings.keepMtime).onChange((t=>{this.plugin.settings.keepMtime=t,this.plugin.saveSettings()}))));const i=e.createDiv("coffee");i.addClass("oz-coffee-div");i.createEl("a",{href:"https://ko-fi.com/L3L356V6Q"}).createEl("img",{attr:{src:"https://cdn.ko-fi.com/cdn/kofi2.png?v=3"}}).height=45}}const o=(t,i)=>e(void 0,void 0,void 0,(function*(){const e=[];let n=yield i.app.vault.read(t),o=n.match(/\[\[.*?\]\]/g);if(o){let i=/(?<=\[\[).*?(?=(\]|\|))/,n=/(?<=\|).*(?=]])/;for(let a of o){if(M(a)){let i=x(a),n=A(a);if(""!==i&&""!==n){let o={type:"wikiTransclusion",match:a,linkText:i,altOrBlockRef:n,sourceFilePath:t.path};e.push(o);continue}}let o=a.match(i);if(o){if(o[0].startsWith("http"))continue;let i=a.match(n),l={type:"wiki",match:a,linkText:o[0],altOrBlockRef:i?i[0]:"",sourceFilePath:t.path};e.push(l)}}}let a=n.match(/\[(^$|.*?)\]\((.*?)\)/g);if(a){let i=/(?<=\().*(?=\))/,n=/(?<=\[)(^$|.*?)(?=\])/;for(let o of a){if(y(o)){let i=x(o),n=A(o);if(""!==i&&""!==n){let a={type:"mdTransclusion",match:o,linkText:i,altOrBlockRef:n,sourceFilePath:t.path};e.push(a);continue}}let a=o.match(i);if(a){if(a[0].startsWith("http"))continue;let i=o.match(n),l={type:"markdown",match:o,linkText:a[0],altOrBlockRef:i?i[0]:"",sourceFilePath:t.path};e.push(l)}}}return e})),a=(i,n,o)=>e(void 0,void 0,void 0,(function*(){let e=yield n.app.vault.read(i),a="markdown"===o?yield c(e,i,n):yield h(e,i,n),l=n.settings.keepMtime?yield n.app.vault.adapter.stat(t.normalizePath(i.path)):{};yield n.app.vault.modify(i,a,l)})),l=(i,n)=>e(void 0,void 0,void 0,(function*(){let e=i.app.workspace.getActiveFile();"md"===e.extension?yield a(e,i,n):new t.Notice("Active File is not a Markdown File")})),s=(i,n,o)=>e(void 0,void 0,void 0,(function*(){let e=((e,i)=>{var n=[];return function e(i,o){var a=o.vault.getAbstractFileByPath(i);if(a instanceof t.TFolder&&a.children)for(let i of a.children)i instanceof t.TFile&&"md"===i.extension&&n.push(i),i instanceof t.TFolder&&e(i.path,o)}(e,i.app),n})(i.path,n),l=new t.Notice("Starting link conversion",0);try{let t=e.length,i=0;for(let s of e)i++,l.setMessage(`Converting the links in notes ${i}/${t}.`),d(n.app,s.path,"excalidraw-plugin")||d(n.app,s.path,"kanban-plugin")||(yield a(s,n,o))}catch(t){console.log(t)}finally{l.hide()}})),r=(i,n)=>e(void 0,void 0,void 0,(fun
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZXMiOlsibm9kZV9tb2R1bGVzL3RzbGliL3RzbGliLmVzNi5qcyIsInNyYy9zZXR0aW5ncy50cyIsInNyYy91dGlscy50cyIsInNyYy9jb252ZXJ0ZXIudHMiLCJzcmMvbW9kYWxzLnRzIiwic3JjL21haW4udHMiLCJzcmMvaWNvbnMudHMiXSwic291cmNlc0NvbnRlbnQiOm51bGwsIm5hbWVzIjpbIl9fYXdhaXRlciIsInRoaXNBcmciLCJfYXJndW1lbnRzIiwiUCIsImdlbmVyYXRvciIsIlByb21pc2UiLCJyZXNvbHZlIiwicmVqZWN0IiwiZnVsZmlsbGVkIiwidmFsdWUiLCJzdGVwIiwibmV4dCIsImUiLCJyZWplY3RlZCIsInJlc3VsdCIsImRvbmUiLCJ0aGVuIiwiYXBwbHkiLCJTdXBwcmVzc2VkRXJyb3IiLCJERUZBVUxUX1NFVFRJTkdTIiwibXlTZXR0aW5nIiwiY29udGV4dE1lbnUiLCJmaW5hbExpbmtGb3JtYXQiLCJrZWVwTXRpbWUiLCJMaW5rQ29udmVydGVyU2V0dGluZ3NUYWIiLCJQbHVnaW5TZXR0aW5nVGFiIiwiY29uc3RydWN0b3IiLCJhcHAiLCJwbHVnaW4iLCJzdXBlciIsInRoaXMiLCJkaXNwbGF5IiwiY29udGFpbmVyRWwiLCJlbXB0eSIsImNyZWF0ZUVsIiwidGV4dCIsIlNldHRpbmciLCJzZXROYW1lIiwic2V0RGVzYyIsImFkZFRvZ2dsZSIsInRvZ2dsZSIsInNldFZhbHVlIiwic2V0dGluZ3MiLCJvbkNoYW5nZSIsIm5ld1ZhbCIsInN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