8 lines
5.6 KiB
JavaScript
8 lines
5.6 KiB
JavaScript
/*
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
if you want to view the source, please visit the github repository of this plugin
|
|
*/
|
|
|
|
var m=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var v=(h,p)=>{for(var e in p)m(h,e,{get:p[e],enumerable:!0})},y=(h,p,e,l)=>{if(p&&typeof p=="object"||typeof p=="function")for(let s of w(p))!P.call(h,s)&&s!==e&&m(h,s,{get:()=>p[s],enumerable:!(l=T(p,s))||l.enumerable});return h};var F=h=>y(m({},"__esModule",{value:!0}),h);var C={};v(C,{default:()=>c});module.exports=F(C);var t=require("obsidian"),S={defaultTemplate:"",folderTemplates:{},ignorePaths:[]},c=class extends t.Plugin{async onload(){await this.loadSettings(),this.app.workspace.onLayoutReady(()=>{this.registerEvent(this.app.vault.on("create",async e=>{if(!(e instanceof t.TFile)||e.extension!=="md")return;let l=(0,t.normalizePath)(e.path);if(this.settings.ignorePaths.some(n=>{let i=(0,t.normalizePath)(n);return l===i||l.startsWith(i+"/")}))return;let a=(n=>{let i=n.split("/").slice(0,-1);for(;i.length>0;){let o=i.join("/"),g=this.settings.folderTemplates[o];if(g){let d=this.app.vault.getAbstractFileByPath(g);if(d instanceof t.TFile)return d}i.pop()}if(this.settings.defaultTemplate){let o=this.app.vault.getAbstractFileByPath(this.settings.defaultTemplate);if(o instanceof t.TFile)return o}})(e.path);if(!a){new t.Notice("No template configured. Go to settings to select one.");return}try{let n=await this.app.vault.read(a);await this.app.vault.process(e,i=>i.trim().length!==0?i:n.replace(/\{\{date(?::([^}]+))?\}\}/g,(g,d)=>d?(0,t.moment)().format(d):(0,t.moment)().format("YYYY-MM-DD")).replace(/\{\{time(?::([^}]+))?\}\}/g,(g,d)=>d?(0,t.moment)().format(d):(0,t.moment)().format("HH:mm")).replace(/\{\{title\}\}/g,e.basename))}catch(n){new t.Notice(`Default Template: Template file "${a.path}" not found or cannot be read.`)}}))}),this.addSettingTab(new f(this.app,this))}onunload(){}async loadSettings(){this.settings=Object.assign({},S,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}},u=class extends t.AbstractInputSuggest{constructor(e,l,s){super(e,l);this.inputEl=l;this.getSuggestionsFn=s}getSuggestions(e){return this.getSuggestionsFn(this.app.vault,e.toLowerCase())}renderSuggestion(e,l){l.createEl("div",{text:e.path})}selectSuggestion(e){this.inputEl.value=e.path,this.inputEl.trigger("input"),this.close()}},f=class extends t.PluginSettingTab{constructor(e,l){super(e,l);this.plugin=l}display(){let{containerEl:e}=this;e.empty(),new t.Setting(e).setName("Default template file").setDesc("Select a template file to apply to new empty notes").addText(s=>{s.setPlaceholder("path/to/template.md").setValue(this.plugin.settings.defaultTemplate).onChange(async r=>{this.plugin.settings.defaultTemplate=(0,t.normalizePath)(r),await this.plugin.saveSettings()}),new u(this.app,s.inputEl,(r,a)=>r.getMarkdownFiles().filter(n=>n.path.toLowerCase().includes(a)))}),new t.Setting(e).setName("Folder templates").setHeading(),e.createEl("p",{text:"Override the default template for specific folders",cls:"setting-item-description"});let l=Object.entries(this.plugin.settings.folderTemplates);for(let[s,r]of l)new t.Setting(e).setName(`Folder: ${s}`).addText(a=>{a.setPlaceholder("Folder/path").setValue(s).onChange(async i=>{let o=(0,t.normalizePath)(i);o!==s&&(delete this.plugin.settings.folderTemplates[s],o&&(this.plugin.settings.folderTemplates[o]=r),await this.plugin.saveSettings())});let n=Object.keys(this.plugin.settings.folderTemplates);new u(this.app,a.inputEl,(i,o)=>i.getAllLoadedFiles().filter(g=>g instanceof t.TFolder).filter(g=>!n.includes(g.path)||g.path===s).filter(g=>g.path.toLowerCase().includes(o)))}).addText(a=>{a.setPlaceholder("path/to/template.md").setValue(r).onChange(async n=>{this.plugin.settings.folderTemplates[s]=(0,t.normalizePath)(n),await this.plugin.saveSettings()}),new u(this.app,a.inputEl,(n,i)=>n.getMarkdownFiles().filter(o=>o.path.toLowerCase().includes(i)))}).addExtraButton(a=>a.setIcon("trash").setTooltip("Delete folder template").onClick(async()=>{delete this.plugin.settings.folderTemplates[s],await this.plugin.saveSettings(),this.display()}));new t.Setting(e).addButton(s=>s.setButtonText("Add folder template").setCta().onClick(async()=>{this.plugin.settings.folderTemplates[""]="",await this.plugin.saveSettings(),this.display()})),new t.Setting(e).setName("Ignore paths").setHeading(),e.createEl("p",{text:"Folders where templates will not be applied",cls:"setting-item-description"});for(let s of this.plugin.settings.ignorePaths)new t.Setting(e).setName(s||"").addText(r=>{r.setPlaceholder("Folder/path").setValue(s).onChange(async a=>{let n=(0,t.normalizePath)(a),i=this.plugin.settings.ignorePaths.indexOf(s);n?!this.plugin.settings.ignorePaths.includes(n)||this.plugin.settings.ignorePaths[i]===n?(this.plugin.settings.ignorePaths[i]=n,await this.plugin.saveSettings()):new t.Notice("Path already ignored"):(this.plugin.settings.ignorePaths.splice(i,1),await this.plugin.saveSettings(),this.display())}),new u(this.app,r.inputEl,(a,n)=>a.getAllLoadedFiles().filter(i=>i instanceof t.TFolder).filter(i=>i.path&&i.path!=="/").filter(i=>i.path.toLowerCase().includes(n)))}).addExtraButton(r=>r.setIcon("trash").setTooltip("Remove").onClick(async()=>{let a=this.plugin.settings.ignorePaths.indexOf(s);this.plugin.settings.ignorePaths.splice(a,1),await this.plugin.saveSettings(),this.display()}));new t.Setting(e).addButton(s=>s.setButtonText("Add ignore path").setCta().onClick(async()=>{this.plugin.settings.ignorePaths.includes("")||(this.plugin.settings.ignorePaths.push(""),await this.plugin.saveSettings(),this.display())}))}};
|
|
|
|
/* nosourcemap */ |