Last active
February 5, 2025 05:59
-
-
Save hyperfocus1337/23b7efff7f8c1dcb0d8c36ac044b98d1 to your computer and use it in GitHub Desktop.
Obsidian templater template that creates markdown front matter using the Denote file name convention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%* | |
identifier = tp.date.now("YYYYMMDDTHHmmss"); // Generate unique identifier based on current timestamp | |
date = tp.date.now("YYYY-MM-DDTHH:mm:ssZ"); // ISO format date | |
title = await tp.system.prompt("Title"); // Prompt user for a title | |
tags = await tp.system.prompt("Tags"); // Prompt user for comma or space-separated tags | |
// Convert tags to an array by splitting on commas or spaces, remove extra spaces, and format them | |
tags_array = tags.split(/[,\s]+/).filter(tag => tag.trim()).map(tag => tag.toLowerCase().trim()); | |
// Format the tags into a slug format for the filename | |
tags_slug = tags_array.join("_"); | |
// Construct the file name (replace whitespaces in title with hyphens and append processed tags) | |
file_name = identifier + "--" + title.replace(/\s+/g, "-").toLowerCase() + "__" + tags_slug; | |
// Rename the file with the constructed file name | |
await tp.file.rename(file_name); | |
// Join the tags array into a new format where each tag is on a new line prefixed by "- " | |
formatted_tags = tags_array.map(tag => ` - ${tag}`).join("\n"); | |
// Format the title with spaces (replace hyphens with spaces) | |
title_with_spaces = title.replace(/-/g, " "); | |
_%> | |
<% "---" %> | |
title: <% title_with_spaces %> | |
date: <% date %> | |
tags: | |
<% formatted_tags %> | |
identifier: <% identifier %> | |
<% "---" %> | |
<% tp.file.cursor() %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment