Skip to content

Commit

Permalink
Merge pull request #14 from numeroflip/support-templater-plugin
Browse files Browse the repository at this point in the history
add support for templater plugin
  • Loading branch information
numeroflip authored Jan 2, 2024
2 parents 89dc62e + 7d06212 commit 395d7f9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
49 changes: 47 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class AutoTemplatePromptPlugin extends Plugin {
const shouldTriggerPrompt = await this.shouldTriggerTemplatePrompt(file)

if (shouldTriggerPrompt) {
this.insertTemplate();
this.triggerTemplatePrompt();
}
}))
}
Expand Down Expand Up @@ -52,9 +52,41 @@ export default class AutoTemplatePromptPlugin extends Plugin {
return false;
}

if (this.shouldPreventTriggerIfTemplaterPluginUsed(file)) {
return false
}

return true
}

shouldPreventTriggerIfTemplaterPluginUsed(file: TFile){
//@ts-expect-error: app.plugins.plugins is not typed globally
const templaterPlugin = this.app.plugins?.plugins?.["templater-obsidian"] as TemplaterPlugin
if (!templaterPlugin) {
return false
}

const areTemplaterFoldersEnabled = !!templaterPlugin?.settings?.enable_folder_templates

if (!areTemplaterFoldersEnabled) {
return false
}

const templaterFolders = templaterPlugin?.settings?.folder_templates.map(({folder}) => folder)

if (!Array.isArray(templaterFolders)) {
return false
}

const isFileInTemplaterFolder = templaterFolders.some((templaterFolder) => file.path.startsWith(templaterFolder + '/'))

if (isFileInTemplaterFolder) {
return true
}

return false
}

async getTemplatesFolder() {
//@ts-expect-error
const templatesSettings = await this.app.vault.readConfigJson('templates')
Expand All @@ -65,8 +97,21 @@ export default class AutoTemplatePromptPlugin extends Plugin {
return file.path.endsWith('.md')
}

insertTemplate() {
triggerTemplatePrompt() {
//@ts-expect-error
this.app.commands.executeCommandById('insert-template');
}
}


interface TemplaterFolder {
folder: string,
template: string
}

interface TemplaterPlugin {
settings?: {
enable_folder_templates: boolean,
folder_templates: TemplaterFolder[]
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "auto-template-trigger",
"name": "Auto Template Trigger",
"version": "1.1.2",
"version": "1.1.3",
"minAppVersion": "1.2.0",
"description": "Automatically prompt for a template, when creating a note.",
"author": "Numeroflip",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-template-trigger",
"version": "1.1.2",
"version": "1.1.3",
"description": "Automatically prompt for a template, when creating a note.",
"main": "main.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"1.0.6": "1.2.0",
"1.1.0": "1.2.0",
"1.1.1": "1.2.0",
"1.1.2": "1.2.0"
"1.1.2": "1.2.0",
"1.1.3": "1.2.0"
}

0 comments on commit 395d7f9

Please sign in to comment.