Skip to content

Commit

Permalink
feat: tags yaml list (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbalasko authored Apr 16, 2024
1 parent a17d7c3 commit c8a6ff3
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 49 deletions.
1 change: 1 addition & 0 deletions Templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ A custom template file can have any file name and extension.
|-|-|-|
| Title | `{title-block}{title}{end-title-block}` | Note title |
| Tags | `{tags-block}{tags}{end-tags-block}` | Note tags |
| Tags as Yaml list | `{tags-yaml-list-block}tags: {tags-yaml-list}{end-tags-yaml-list-block}` | Note tags as yaml list
| Array Tags |`{tags-array-block}{tags-array}{end-tags-array-block}` | Note tags in array format (to be compatible with Obsidian's Yaml Frontmatter)
| Content | `{content-block}{content}{end-content-block}` | Note content |
| Date of creation | `{created-at-block}{created-at}{end-created-at-block}` | Creation date of the note |
Expand Down
58 changes: 19 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sampleTemplate.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{created-at-block}Created at: {created-at}{end-created-at-block}
{updated-at-block}Last updated at: {updated-at}{end-updated-at-block}
{source-url-block}Source URL: {source-url}{end-source-url-block}
{tags-block}tags: {tags}{end-tags-block}
{tags-yaml-list-block}tags: {tags-yaml-list}{end-tags-yaml-list-block}

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { applyTemplateOnBlock } from './apply-template-on-block';
import { getTemplateBlockSettings } from './get-templateblock-settings';
export const applyTagsArrayTemplate = (noteData: NoteData, inputText: string, check: Function): string => {
const result = cloneDeep(inputText);
let tags = noteData.tags ? JSON.stringify(noteData.tags.split(' ')) : undefined;

if (noteData.tags) {
noteData.tags = JSON.stringify(noteData.tags.split(' '));
}
const tagsTemplateSettings = getTemplateBlockSettings(result, check, P, noteData.tags);
const tagsTemplateSettings = getTemplateBlockSettings(result, check, P, tags);

return applyTemplateOnBlock(tagsTemplateSettings);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NoteData } from '../../../models/NoteData';
import * as P from '../placeholders/tags-yaml-list-placeholders';

import { applyTemplateOnBlock } from './apply-template-on-block';
import { getTemplateBlockSettings } from './get-templateblock-settings';

export const applyTagsYamlListTemplate = (noteData: NoteData, inputText: string, check: Function): string => {
let tags;
if (noteData.tags) {
tags = '\n'+noteData.tags.split(' ').map((tag:string) => ` - ${tag.replace(/^#/, '')}`).join('\n');
}
const tagsTemplateSettings = getTemplateBlockSettings(inputText, check, P, tags);

return applyTemplateOnBlock(tagsTemplateSettings);

};
3 changes: 2 additions & 1 deletion src/utils/templates/apply-functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export * from './apply-reminderorder-template';
export * from './apply-reminderdonetime-template';
export * from './apply-tags-array-template';
export * from './apply-evernotelink-template';
export * from './apply-evernoteguid-template';
export * from './apply-evernoteguid-template';
export * from './apply-tags-yaml-list-template';
Loading

0 comments on commit c8a6ff3

Please sign in to comment.