-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathnew-note-template.ts
More file actions
16 lines (14 loc) · 690 Bytes
/
Copy pathnew-note-template.ts
File metadata and controls
16 lines (14 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { isSpecialTag } from "./util";
export function renderTagFolderTemplateVariables(template: string, expandedTagsAll: string[], expandedTags: string) {
const plainTags = expandedTagsAll.filter(e => !isSpecialTag(e));
const replacements: Record<string, string> = {
expandedTags,
tags: expandedTags,
tagList: plainTags.join(", "),
tagPath: plainTags.join("/"),
tagName: plainTags[plainTags.length - 1] ?? "",
tagsJson: JSON.stringify(plainTags),
tagsYaml: plainTags.map((tag) => ` - ${tag}`).join("\n"),
};
return template.replace(/\{\{(expandedTags|tags|tagList|tagPath|tagName|tagsJson|tagsYaml)\}\}/g, (_, key: keyof typeof replacements) => replacements[key]);
}