Add Template by Rename setting back in, consolidate template prepend logic (#60)

* Add template on rename events, disabled by default

Also consolidates rename and creation prepend logic
to ensure we're always atomically reading the content of the notes for both create and rename events

* Release 1.1.3
This commit is contained in:
Jacob Learned 2024-12-20 23:55:13 -06:00 committed by GitHub
parent 71b8f18605
commit 0c13dae74d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 123 additions and 44 deletions

View file

@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.1.3] - 2024-12-20
### Fixed
- Adds "template on rename" setting back into settings, disabled by default.
- Consolidates template prepend logic to ensure both note creation and rename
events atomically read the content of an existing note before prepending a template.
## [1.1.2] - 2024-12-19
### Fixed

View file

@ -3,7 +3,7 @@
<a href="https://www.buymeacoffee.com/jacoblearned" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" alt="Buy Me A Coffee" style="height: 40px !important;width: 150px !important;" ></a>
This is a simple [Obsidian](https://obsidian.md/) plugin to automatically template notes
based on their name when created. Users can template notes that match
based on their name when created or renamed. Users can template notes that match
their desired naming conventions with any template that exists in their
specified templates folder (including sub-folders).
@ -18,6 +18,8 @@ Examples:
- **Quicker templating**: Automatically template notes based on their name at creation time
- **Customizable**: Users can create rules to template notes based on their personal naming conventions
- **Multiple match options**: Choose from prefix, suffix, or contains to template notes
- **Optionally template on rename**: Choose whether or not to template notes when they are renamed
If a note is renamed to a matching template, the template content will be prepended to the existing note.
- **Case sensitivity options**: Choose whether or not to match note names against rules in a case-sensitive manner
## Installation

View file

@ -1 +1 @@
window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAAE62YTW/jNhCG/8vkSiQeWv7SsVsE6GG3RRP0IhgLVaITofowJNrbheH/XlAWzaHJ2KycmyHP+86QfDgidYC2+dFBnBzgn6LOIeazOYM6rQTE8DWV2btogcGuLSGGopai3aSZ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n3Cbkj5JZwBiyZ+YQzRzizhHNgydwnnDvCuSVcAEsWPuHCES4s4RJYsvQJl45waQlXwJKVT7hyhCtLGAFLIsZnk9V6YQkjRxhZwjWwZO3LuHaEaxsAxQN62UEXHrygp8fHz48HIJsgVFyglyF0IUKbIlRsoJcjdEFCmyRUfKCXJXRhQpsmVIyglyd0gUKbKFScoJcpdKFCmypUrKCXK3TBQpssVLxg5BW7cKFNFypm0MsXuoChTRhXzHAvYdwljNuEcXxvR3AXMH7Rovoe5aWTe7qUDRhXyHB/h3MB4zZgXCHDvXRyFzBuA8YVMtxLJ3cBGx71Z8tBtFLkv53PmCSBi3vaEf4azp+1PuOOsIb4eDqZ0yY+nsiBo37r05Gbu7FZGptlmI2+UhkPRGOCGOTivlMTO1IThhXl3EiI25y4zQPd3GsVMZwRw1mQoe/mQgwXxHARZGi/iBkrzo0VD6ut0l8tjcvUmEw/4mGVgsQFP2CjP/QZJzLfHxiS/iBKKiIFBfno12oyv8SD80CTvWtDmORhK25fCcmgVmRUq49YDfc9YhURqyjIyn5FJwMka8bDNp3PBgnOGDbdep/9/VNdMJXYZ0zmP6y6y6+xxops3rCVtC/AZLCko2NYS3dvtmQJyP7jYfvPvbIaO8JGdJbzsE1k/7eA1EfKCzMin3mNDcE/gP4Ng12xE2VRC4iTzen0Px7cOmDRGQAA";

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
<!DOCTYPE html><html class="default" lang="en" data-base="."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>obsidian-template-by-note-name</title><meta name="description" content="Documentation for obsidian-template-by-note-name"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">obsidian-template-by-note-name</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>obsidian-template-by-note-name</h1></div><div class="tsd-panel tsd-typography"><a id="template-by-note-name" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Template by Note Name<a href="#template-by-note-name" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><p><a href="https://www.buymeacoffee.com/jacoblearned" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" alt="Buy Me A Coffee" style="height: 40px !important;width: 150px !important;" ></a></p>
<p>This is a simple <a href="https://obsidian.md/" target="_blank" class="external">Obsidian</a> plugin to automatically template notes
based on their name when created. Users can template notes that match
based on their name when created or renamed. Users can template notes that match
their desired naming conventions with any template that exists in their
specified templates folder (including sub-folders).</p>
<p>Examples:</p>
@ -13,6 +13,8 @@ specified templates folder (including sub-folders).</p>
<li><strong>Quicker templating</strong>: Automatically template notes based on their name at creation time</li>
<li><strong>Customizable</strong>: Users can create rules to template notes based on their personal naming conventions</li>
<li><strong>Multiple match options</strong>: Choose from prefix, suffix, or contains to template notes</li>
<li><strong>Optionally template on rename</strong>: Choose whether or not to template notes when they are renamed
If a note is renamed to a matching template, the template content will be prepended to the existing note.</li>
<li><strong>Case sensitivity options</strong>: Choose whether or not to match note names against rules in a case-sensitive manner</li>
</ul>
<a id="installation" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Installation<a href="#installation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>You can install the plugin via the Community Plugins tab within Obsidian or by <a href="https://obsidian.md/plugins?id=template-by-note-name" target="_blank" class="external">direct link here</a>.</p>

File diff suppressed because one or more lines are too long

View file

@ -1,12 +1,14 @@
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>TemplateByNoteNameSettings | obsidian-template-by-note-name</title><meta name="description" content="Documentation for obsidian-template-by-note-name"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">obsidian-template-by-note-name</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">obsidian-template-by-note-name</a></li><li><a href="TemplateByNoteNameSettings.html">TemplateByNoteNameSettings</a></li></ul><h1>Interface TemplateByNoteNameSettings</h1></div><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><p>TemplateByNoteNameSettings represents the user-provided settings for the plugin.</p>
</div><div class="tsd-comment tsd-typography"></div></section><div class="tsd-signature"><span class="tsd-signature-keyword">interface</span> <span class="tsd-kind-interface">TemplateByNoteNameSettings</span> <span class="tsd-signature-symbol">{</span><br/>    <a class="tsd-kind-property" href="TemplateByNoteNameSettings.html#casesensitive">caseSensitive</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">;</span><br/>    <a class="tsd-kind-property" href="TemplateByNoteNameSettings.html#dateformat">dateFormat</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/>    <a class="tsd-kind-property" href="TemplateByNoteNameSettings.html#matchers">matchers</a><span class="tsd-signature-symbol">:</span> <a href="Matcher.html" class="tsd-signature-type tsd-kind-interface">Matcher</a><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">;</span><br/>    <a class="tsd-kind-property" href="TemplateByNoteNameSettings.html#templatefolder">templateFolder</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/>    <a class="tsd-kind-property" href="TemplateByNoteNameSettings.html#timeformat">timeFormat</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/><span class="tsd-signature-symbol">}</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/5bc8dbd7396d22c0bb8a8525af92d6a01fe2a15a/src/main.ts#L25">src/main.ts:25</a></li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabIndex="0"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-chevronSmall"></use></svg> Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="TemplateByNoteNameSettings.html#casesensitive" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>case<wbr/>Sensitive</span></a>
</div><div class="tsd-comment tsd-typography"></div></section><div class="tsd-signature"><span class="tsd-signature-keyword">interface</span> <span class="tsd-kind-interface">TemplateByNoteNameSettings</span> <span class="tsd-signature-symbol">{</span><br/>    <a class="tsd-kind-property" href="TemplateByNoteNameSettings.html#casesensitive">caseSensitive</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">;</span><br/>    <a class="tsd-kind-property" href="TemplateByNoteNameSettings.html#dateformat">dateFormat</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/>    <a class="tsd-kind-property" href="TemplateByNoteNameSettings.html#matchers">matchers</a><span class="tsd-signature-symbol">:</span> <a href="Matcher.html" class="tsd-signature-type tsd-kind-interface">Matcher</a><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">;</span><br/>    <a class="tsd-kind-property" href="TemplateByNoteNameSettings.html#templatefolder">templateFolder</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/>    <a class="tsd-kind-property" href="TemplateByNoteNameSettings.html#templateonrename">templateOnRename</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">;</span><br/>    <a class="tsd-kind-property" href="TemplateByNoteNameSettings.html#timeformat">timeFormat</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/><span class="tsd-signature-symbol">}</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/c0cbad3266f2f9b6f3833aff11a6b1ff04112184/src/main.ts#L25">src/main.ts:25</a></li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabIndex="0"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-chevronSmall"></use></svg> Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="TemplateByNoteNameSettings.html#casesensitive" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>case<wbr/>Sensitive</span></a>
<a href="TemplateByNoteNameSettings.html#dateformat" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>date<wbr/>Format</span></a>
<a href="TemplateByNoteNameSettings.html#matchers" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>matchers</span></a>
<a href="TemplateByNoteNameSettings.html#templatefolder" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>template<wbr/>Folder</span></a>
<a href="TemplateByNoteNameSettings.html#templateonrename" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>template<wbr/>On<wbr/>Rename</span></a>
<a href="TemplateByNoteNameSettings.html#timeformat" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>time<wbr/>Format</span></a>
</div></section></div></details></section></section><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Properties"><h2><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg> Properties</h2></summary><section><section class="tsd-panel tsd-member"><a id="casesensitive" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>case<wbr/>Sensitive</span><a href="#casesensitive" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">caseSensitive</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div><div class="tsd-comment tsd-typography"><p>Whether to match note names against user-provided rule match strings in a case-sensitive manner</p>
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/5bc8dbd7396d22c0bb8a8525af92d6a01fe2a15a/src/main.ts#L36">src/main.ts:36</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="dateformat" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>date<wbr/>Format</span><a href="#dateformat" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">dateFormat</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>Date format used in templates</p>
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/5bc8dbd7396d22c0bb8a8525af92d6a01fe2a15a/src/main.ts#L30">src/main.ts:30</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="matchers" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>matchers</span><a href="#matchers" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">matchers</span><span class="tsd-signature-symbol">:</span> <a href="Matcher.html" class="tsd-signature-type tsd-kind-interface">Matcher</a><span class="tsd-signature-symbol">[]</span></div><div class="tsd-comment tsd-typography"><p>Collection of user-provided matching rules to determine which template to apply to a new or renamed note</p>
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/5bc8dbd7396d22c0bb8a8525af92d6a01fe2a15a/src/main.ts#L39">src/main.ts:39</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="templatefolder" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>template<wbr/>Folder</span><a href="#templatefolder" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">templateFolder</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>Path to folder from vault root where user stores their templates</p>
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/5bc8dbd7396d22c0bb8a8525af92d6a01fe2a15a/src/main.ts#L27">src/main.ts:27</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="timeformat" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>time<wbr/>Format</span><a href="#timeformat" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">timeFormat</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>Whether to apply a template to a note when it is renamed to match a rule</p>
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/5bc8dbd7396d22c0bb8a8525af92d6a01fe2a15a/src/main.ts#L33">src/main.ts:33</a></li></ul></aside></section></section></details></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Properties"><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Properties</summary><div><a href="#casesensitive" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>case<wbr/>Sensitive</span></a><a href="#dateformat" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>date<wbr/>Format</span></a><a href="#matchers" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>matchers</span></a><a href="#templatefolder" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>template<wbr/>Folder</span></a><a href="#timeformat" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>time<wbr/>Format</span></a></div></details></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">obsidian-template-by-note-name</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/c0cbad3266f2f9b6f3833aff11a6b1ff04112184/src/main.ts#L39">src/main.ts:39</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="dateformat" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>date<wbr/>Format</span><a href="#dateformat" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">dateFormat</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>Date format used in templates</p>
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/c0cbad3266f2f9b6f3833aff11a6b1ff04112184/src/main.ts#L30">src/main.ts:30</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="matchers" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>matchers</span><a href="#matchers" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">matchers</span><span class="tsd-signature-symbol">:</span> <a href="Matcher.html" class="tsd-signature-type tsd-kind-interface">Matcher</a><span class="tsd-signature-symbol">[]</span></div><div class="tsd-comment tsd-typography"><p>Collection of user-provided matching rules to determine which template to apply to a new or renamed note</p>
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/c0cbad3266f2f9b6f3833aff11a6b1ff04112184/src/main.ts#L42">src/main.ts:42</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="templatefolder" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>template<wbr/>Folder</span><a href="#templatefolder" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">templateFolder</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>Path to folder from vault root where user stores their templates</p>
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/c0cbad3266f2f9b6f3833aff11a6b1ff04112184/src/main.ts#L27">src/main.ts:27</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="templateonrename" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>template<wbr/>On<wbr/>Rename</span><a href="#templateonrename" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">templateOnRename</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div><div class="tsd-comment tsd-typography"><p>Whether to apply a template to a note when it is renamed to match a rule</p>
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/c0cbad3266f2f9b6f3833aff11a6b1ff04112184/src/main.ts#L36">src/main.ts:36</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="timeformat" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>time<wbr/>Format</span><a href="#timeformat" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">timeFormat</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>Whether to apply a template to a note when it is renamed to match a rule</p>
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/jacoblearned/obsidian-template-by-note-name/blob/c0cbad3266f2f9b6f3833aff11a6b1ff04112184/src/main.ts#L33">src/main.ts:33</a></li></ul></aside></section></section></details></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Properties"><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Properties</summary><div><a href="#casesensitive" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>case<wbr/>Sensitive</span></a><a href="#dateformat" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>date<wbr/>Format</span></a><a href="#matchers" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>matchers</span></a><a href="#templatefolder" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>template<wbr/>Folder</span></a><a href="#templateonrename" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>template<wbr/>On<wbr/>Rename</span></a><a href="#timeformat" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>time<wbr/>Format</span></a></div></details></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">obsidian-template-by-note-name</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>

View file

@ -1,7 +1,7 @@
{
"id": "template-by-note-name",
"name": "Template by Note Name",
"version": "1.1.2",
"version": "1.1.3",
"minAppVersion": "0.15.0",
"description": "Automatically template notes based on their title.",
"author": "Jacob Learned",

View file

@ -1,6 +1,6 @@
{
"name": "obsidian-template-by-note-name",
"version": "1.1.2",
"version": "1.1.3",
"description": "Obsidian plugin for automatically templating notes based on their name",
"main": "main.js",
"type": "module",

View file

@ -32,6 +32,9 @@ export interface TemplateByNoteNameSettings {
/** Whether to apply a template to a note when it is renamed to match a rule */
timeFormat: string;
/** Whether to apply a template to a note when it is renamed to match a rule */
templateOnRename: boolean;
/** Whether to match note names against user-provided rule match strings in a case-sensitive manner */
caseSensitive: boolean;
@ -43,6 +46,7 @@ const DEFAULT_SETTINGS: TemplateByNoteNameSettings = {
templateFolder: "Templates",
dateFormat: "YYYY-MM-DD",
timeFormat: "HH:mm",
templateOnRename: false,
caseSensitive: true,
matchers: [],
};
@ -55,15 +59,6 @@ export default class TemplateByNoteNamePlugin extends Plugin {
/** Collection of user-provided settings values set in plugin settings tab */
settings: TemplateByNoteNameSettings;
/**
* Write the given content to the provided file.
* @param file The Obsidian file object representing an existing note
* @param content The content to write to the note, overwriting the existing content
*/
async writeToFile(file: TFile, content: string) {
await this.app.vault.modify(file, content);
}
/**
* Find the first Matcher instance in the user-provided settings that matches the given file.
* @param file The Obsidian file object representing an existing note
@ -180,15 +175,56 @@ export default class TemplateByNoteNamePlugin extends Plugin {
}
/**
* Apply a template to a new note if the note name matches a user-provided rule.
* Prepend the content of a template note to a note.
* @param file The Obsidian file object representing an existing note
* @param templatePath Full path to a template note from the vault root
*/
async templateNote(file: TFile, templatePath: string) {
const templateContent = await this.getTemplateContent(templatePath);
const fileContent = await this.app.vault.read(file);
await this.app.vault.modify(
file,
`${templateContent}\n\n${fileContent}`,
);
}
/**
* Apply a template to a newly created note if the note name matches a user-provided rule.
* @param file The Obsidian file object representing the newly created note
*/
async templateOnCreate(file: TFile) {
const templatePath = this.findMatcherForFile(file)?.templatePath;
if (templatePath) {
const templateContent = await this.getTemplateContent(templatePath);
await this.writeToFile(file, templateContent);
await this.templateNote(file, templatePath);
}
}
/**
* Apply a template to a renamed note if the new name matches a user-provided rule.
* @param file The Obsidian file object representing the renamed note
* @param oldName The full path to the note from the vault root before it was renamed
*/
async templateOnRename(file: TFile, oldName: string) {
const matcher = this.findMatcherForFile(file);
if (matcher) {
if (!this.settings.templateOnRename) {
return;
}
/* We only want to prepend the template content if the note was renamed to match a rule
and the oldName does not match the rule the note now matches.
This prevents the template content from being prepended multiple times on subsequent renames.
oldName is the full path to the note from the vault root, e.g. "Path/To/Note.md"
*/
const oldBaseName = oldName.split("/").pop()?.slice(0, -3) ?? "";
if (this.fileMatchesRule(oldBaseName, matcher)) {
return;
}
await this.templateNote(file, matcher.templatePath);
}
}
@ -206,6 +242,14 @@ export default class TemplateByNoteNamePlugin extends Plugin {
}
}),
);
this.registerEvent(
this.app.vault.on("rename", async (file, oldName) => {
if (file instanceof TFile) {
await this.templateOnRename(file, oldName);
}
}),
);
});
// Adds tab for Template by Note Name under
@ -444,6 +488,22 @@ class TemplateByNoteNameSettingTab extends PluginSettingTab {
new Setting(containerEl).setName("Advanced").setHeading();
new Setting(containerEl)
.setName("Template on rename")
.setDesc(
`When an existing note's name is changed to one that matches a rule, the plugin will prepend the rule's template to the note's content.
This is useful to enable if you frequently rename default "Untitled" notes to match a rule. Be cautious when performing any bulk rename operations
to ensure that the plugin does not prepend the template to notes that you do not intend to.`,
)
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.templateOnRename)
.onChange(async (value) => {
this.plugin.settings.templateOnRename = value;
await this.plugin.saveSettings();
}),
);
new Setting(containerEl)
.setName("Case-Sensitive matching")
.setDesc(

View file

@ -2,5 +2,6 @@
"1.0.0": "0.15.0",
"1.1.0": "0.15.0",
"1.1.1": "0.15.0",
"1.1.2": "0.15.0"
"1.1.2": "0.15.0",
"1.1.3": "0.15.0"
}