Skip to content

Commit c8a6ff3

Browse files
authored
feat: tags yaml list (#629)
1 parent a17d7c3 commit c8a6ff3

13 files changed

+114
-49
lines changed

Templates.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ A custom template file can have any file name and extension.
3131
|-|-|-|
3232
| Title | `{title-block}{title}{end-title-block}` | Note title |
3333
| Tags | `{tags-block}{tags}{end-tags-block}` | Note tags |
34+
| Tags as Yaml list | `{tags-yaml-list-block}tags: {tags-yaml-list}{end-tags-yaml-list-block}` | Note tags as yaml list
3435
| Array Tags |`{tags-array-block}{tags-array}{end-tags-array-block}` | Note tags in array format (to be compatible with Obsidian's Yaml Frontmatter)
3536
| Content | `{content-block}{content}{end-content-block}` | Note content |
3637
| Date of creation | `{created-at-block}{created-at}{end-created-at-block}` | Creation date of the note |

package-lock.json

Lines changed: 19 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sampleTemplate.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{created-at-block}Created at: {created-at}{end-created-at-block}
44
{updated-at-block}Last updated at: {updated-at}{end-updated-at-block}
55
{source-url-block}Source URL: {source-url}{end-source-url-block}
6-
{tags-block}tags: {tags}{end-tags-block}
6+
{tags-yaml-list-block}tags: {tags-yaml-list}{end-tags-yaml-list-block}
77

88
---
99

src/utils/templates/apply-functions/apply-tags-array-template.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import { applyTemplateOnBlock } from './apply-template-on-block';
77
import { getTemplateBlockSettings } from './get-templateblock-settings';
88
export const applyTagsArrayTemplate = (noteData: NoteData, inputText: string, check: Function): string => {
99
const result = cloneDeep(inputText);
10+
let tags = noteData.tags ? JSON.stringify(noteData.tags.split(' ')) : undefined;
1011

11-
if (noteData.tags) {
12-
noteData.tags = JSON.stringify(noteData.tags.split(' '));
13-
}
14-
const tagsTemplateSettings = getTemplateBlockSettings(result, check, P, noteData.tags);
12+
const tagsTemplateSettings = getTemplateBlockSettings(result, check, P, tags);
1513

1614
return applyTemplateOnBlock(tagsTemplateSettings);
1715
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { NoteData } from '../../../models/NoteData';
2+
import * as P from '../placeholders/tags-yaml-list-placeholders';
3+
4+
import { applyTemplateOnBlock } from './apply-template-on-block';
5+
import { getTemplateBlockSettings } from './get-templateblock-settings';
6+
7+
export const applyTagsYamlListTemplate = (noteData: NoteData, inputText: string, check: Function): string => {
8+
let tags;
9+
if (noteData.tags) {
10+
tags = '\n'+noteData.tags.split(' ').map((tag:string) => ` - ${tag.replace(/^#/, '')}`).join('\n');
11+
}
12+
const tagsTemplateSettings = getTemplateBlockSettings(inputText, check, P, tags);
13+
14+
return applyTemplateOnBlock(tagsTemplateSettings);
15+
16+
};

src/utils/templates/apply-functions/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export * from './apply-reminderorder-template';
1212
export * from './apply-reminderdonetime-template';
1313
export * from './apply-tags-array-template';
1414
export * from './apply-evernotelink-template';
15-
export * from './apply-evernoteguid-template';
15+
export * from './apply-evernoteguid-template';
16+
export * from './apply-tags-yaml-list-template';

0 commit comments

Comments
 (0)