diff --git a/main.js b/main.js index cf26d5c7..dc1119e9 100644 --- a/main.js +++ b/main.js @@ -21120,6 +21120,7 @@ const DEFAULT_SETTINGS = { noPathMessage: `This note has no real or implied parents`, threadIntoNewPane: false, threadingTemplate: "{{field}} of {{current}}", + threadingDirTemplates: { up: "", same: "", down: "", next: "", prev: "" }, trailSeperator: "→", treatCurrNodeAsImpliedSibling: false, trimDendronNotes: false, @@ -25712,14 +25713,14 @@ class BCSettingTab extends require$$0.PluginSettingTab { new require$$0.Setting(threadingDetails) .setName("New Note Name Template") .setDesc(fragWithHTML(`When threading into a new note, choose the template for the new note name.
- The default is {{field}} of {{current}}.
- Options include:
- `)) + The default is {{field}} of {{current}}.
+ Options include:
+ `)) .addText((text) => { text.setValue(settings.threadingTemplate); text.inputEl.onblur = async () => { @@ -25727,6 +25728,20 @@ class BCSettingTab extends require$$0.PluginSettingTab { await plugin.saveSettings(); }; }); + const threadDirTemplatesSetting = new require$$0.Setting(threadingDetails) + .setClass("thread-dir-templates") + .setName("Templater Template per Direction") + .setDesc(fragWithHTML(`For each direction to be thread into, choose a Templater template to insert into the new note.
+ Give the basename, or the full file path (e.g. Templates/Parent Template).`)); + DIRECTIONS$1.forEach((dir) => threadDirTemplatesSetting.addText((text) => { + text + .setPlaceholder(ARROW_DIRECTIONS[dir]) + .setValue(settings.threadingDirTemplates[dir]); + text.inputEl.onblur = async () => { + settings.threadingDirTemplates[dir] = text.getValue(); + await plugin.saveSettings(); + }; + })); new require$$0.Setting(threadingDetails) .setName("Date Format") .setDesc("The date format used in the Threading Template (setting above)") @@ -51985,12 +52000,22 @@ class BCPlugin extends require$$0.Plugin { if (i === 1) newBasename += ` ${i}`; else - newBasename = newBasename.slice(0, -1) + ` ${i}`; + newBasename = newBasename.slice(0, -2) + ` ${i}`; i++; } - const newFile = await app.vault.create(require$$0.normalizePath(`${newFileParent.path}/${newBasename}.md`), writeBCsInline + const crumb = writeBCsInline ? `${oppField}:: [[${currFile.basename}]]` - : `---\n${oppField}: ['${currFile.basename}']\n---`); + : `---\n${oppField}: ['${currFile.basename}']\n---`; + const templatePath = settings.threadingDirTemplates[dir]; + let newContent = crumb; + if (templatePath) { + const templateFile = app.metadataCache.getFirstLinkpathDest(templatePath, ""); + const template = await app.vault.cachedRead(templateFile); + newContent = template.replace(/\{\{BC-thread-crumb\}\}/i, writeBCsInline + ? `${oppField}:: [[${currFile.basename}]]` + : `${oppField}: ['${currFile.basename}']`); + } + const newFile = await app.vault.create(require$$0.normalizePath(`${newFileParent.path}/${newBasename}.md`), newContent); if (!writeBCsInline) { const { api } = (_b = app.plugins.plugins.metaedit) !== null && _b !== void 0 ? _b : {}; if (!api) { @@ -52015,6 +52040,12 @@ class BCPlugin extends require$$0.Plugin { ? app.workspace.splitActiveLeaf() : app.workspace.activeLeaf; await leaf.openFile(newFile, { active: true, mode: "source" }); + if (app.plugins.plugins["templater-obsidian"]) { + app.commands.executeCommandById("templater-obsidian:replace-in-file-templater"); + } + else { + new require$$0.Notice("The Templater plugin must be enabled to resolve the templates in the new note"); + } const editor = leaf.view.editor; editor.setCursor(editor.getValue().length); }, diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index e34c9bb6..9cdd9fc6 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -13,7 +13,9 @@ import KoFi from "./Components/KoFi.svelte"; import UserHierarchies from "./Components/UserHierarchies.svelte"; import { ALLUNLINKED, + ARROW_DIRECTIONS, DEFAULT_SETTINGS, + DIRECTIONS, MATRIX_VIEW, REAlCLOSED, RELATIONS, @@ -951,14 +953,14 @@ export class BCSettingTab extends PluginSettingTab { .setDesc( fragWithHTML( `When threading into a new note, choose the template for the new note name.
- The default is {{field}} of {{current}}.
- Options include:
- ` + The default is {{field}} of {{current}}.
+ Options include:
+ ` ) ) .addText((text) => { @@ -968,6 +970,27 @@ export class BCSettingTab extends PluginSettingTab { await plugin.saveSettings(); }; }); + const threadDirTemplatesSetting = new Setting(threadingDetails) + .setClass("thread-dir-templates") + .setName("Templater Template per Direction") + .setDesc( + fragWithHTML( + `For each direction to be thread into, choose a Templater template to insert into the new note.
+ Give the basename, or the full file path (e.g. Templates/Parent Template).` + ) + ); + + DIRECTIONS.forEach((dir) => + threadDirTemplatesSetting.addText((text) => { + text + .setPlaceholder(ARROW_DIRECTIONS[dir]) + .setValue(settings.threadingDirTemplates[dir]); + text.inputEl.onblur = async () => { + settings.threadingDirTemplates[dir] = text.getValue(); + await plugin.saveSettings(); + }; + }) + ); new Setting(threadingDetails) .setName("Date Format") diff --git a/src/constants.ts b/src/constants.ts index 2c89038e..99daf6ef 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -185,6 +185,7 @@ export const DEFAULT_SETTINGS: BCSettings = { noPathMessage: `This note has no real or implied parents`, threadIntoNewPane: false, threadingTemplate: "{{field}} of {{current}}", + threadingDirTemplates: { up: "", same: "", down: "", next: "", prev: "" }, trailSeperator: "→", treatCurrNodeAsImpliedSibling: false, trimDendronNotes: false, diff --git a/src/interfaces.ts b/src/interfaces.ts index 426a04a4..c0ec3624 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -60,6 +60,7 @@ export interface BCSettings { squareDirectionsOrder: (0 | 1 | 2 | 3 | 4)[]; threadIntoNewPane: boolean; threadingTemplate: string; + threadingDirTemplates: { [dir in Directions]: string }; trailSeperator: string; treatCurrNodeAsImpliedSibling: boolean; trimDendronNotes: boolean; diff --git a/src/main.ts b/src/main.ts index 920c0f65..72a98ef6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -455,11 +455,30 @@ export default class BCPlugin extends Plugin { i++; } + const crumb = writeBCsInline + ? `${oppField}:: [[${currFile.basename}]]` + : `---\n${oppField}: ['${currFile.basename}']\n---`; + + const templatePath = settings.threadingDirTemplates[dir]; + let newContent = crumb; + if (templatePath) { + const templateFile = app.metadataCache.getFirstLinkpathDest( + templatePath, + "" + ); + + const template = await app.vault.cachedRead(templateFile); + newContent = template.replace( + /\{\{BC-thread-crumb\}\}/i, + writeBCsInline + ? `${oppField}:: [[${currFile.basename}]]` + : `${oppField}: ['${currFile.basename}']` + ); + } + const newFile = await app.vault.create( normalizePath(`${newFileParent.path}/${newBasename}.md`), - writeBCsInline - ? `${oppField}:: [[${currFile.basename}]]` - : `---\n${oppField}: ['${currFile.basename}']\n---` + newContent ); if (!writeBCsInline) { @@ -496,6 +515,16 @@ export default class BCPlugin extends Plugin { : app.workspace.activeLeaf; await leaf.openFile(newFile, { active: true, mode: "source" }); + if (app.plugins.plugins["templater-obsidian"]) { + app.commands.executeCommandById( + "templater-obsidian:replace-in-file-templater" + ); + } else { + new Notice( + "The Templater plugin must be enabled to resolve the templates in the new note" + ); + } + const editor = leaf.view.editor as Editor; editor.setCursor(editor.getValue().length); }, diff --git a/styles.css b/styles.css index 89a56f68..214ecfb9 100644 --- a/styles.css +++ b/styles.css @@ -88,3 +88,8 @@ visibility: hidden; opacity: 0; } + +.thread-dir-templates .setting-item-control { + display: flex; + flex-direction: column; +}