7 lines
2.8 KiB
JavaScript
7 lines
2.8 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 o=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var T=(s,a)=>{for(var t in a)o(s,t,{get:a[t],enumerable:!0})},w=(s,a,t,n)=>{if(a&&typeof a=="object"||typeof a=="function")for(let l of f(a))!h.call(s,l)&&l!==t&&o(s,l,{get:()=>a[l],enumerable:!(n=d(a,l))||n.enumerable});return s};var D=s=>w(o({},"__esModule",{value:!0}),s);var v={};T(v,{default:()=>p});module.exports=D(v);var e=require("obsidian"),y={defaultTemplate:""},p=class extends e.Plugin{async onload(){await this.loadSettings(),this.registerEvent(this.app.vault.on("create",async t=>{if(!(t instanceof e.TFile)||t.extension!=="md")return;if(!this.settings.defaultTemplate){new e.Notice("Default Template: No template configured. Go to Settings \u2192 Default Template to select one.");return}if((await this.app.vault.read(t)).trim().length!==0)return;let l=this.app.vault.getAbstractFileByPath(this.settings.defaultTemplate);if(!(l instanceof e.TFile)){new e.Notice(`Default Template: Template file "${this.settings.defaultTemplate}" not found. Please select a new template.`);return}try{let c=(await this.app.vault.read(l)).replace(/\{\{date(?::([^}]+))?\}\}/g,(g,i)=>i?(0,e.moment)().format(i):(0,e.moment)().format("YYYY-MM-DD")).replace(/\{\{time(?::([^}]+))?\}\}/g,(g,i)=>i?(0,e.moment)().format(i):(0,e.moment)().format("HH:mm")).replace(/\{\{title\}\}/g,t.basename);await this.app.vault.modify(t,c)}catch(m){new e.Notice(`Default Template: Template file "${this.settings.defaultTemplate}" not found or cannot be read.`)}})),this.addSettingTab(new r(this.app,this))}onunload(){}async loadSettings(){this.settings=Object.assign({},y,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}},u=class extends e.FuzzySuggestModal{constructor(t,n){super(t);this.plugin=n}getItems(){return this.app.vault.getMarkdownFiles()}getItemText(t){return t.path}onChooseItem(t){this.plugin.settings.defaultTemplate=t.path,this.plugin.saveSettings(),new e.Notice(`Default template set to: ${t.path}`)}},r=class extends e.PluginSettingTab{constructor(t,n){super(t,n);this.plugin=n}display(){let{containerEl:t}=this;t.empty(),t.createEl("h2",{text:"Default Template"}),new e.Setting(t).setName("Default template file").setDesc("Select a template file to automatically apply to new empty notes").addButton(n=>n.setButtonText("Select template").onClick(()=>{new u(this.app,this.plugin).open()})),this.plugin.settings.defaultTemplate?t.createEl("div",{text:`\u2713 Active template: ${this.plugin.settings.defaultTemplate}`,cls:"mod-success"}):t.createEl("p",{text:"No template selected. Plugin will not apply any template to new files.",cls:"setting-item-description"})}};
|