Skip to content

Instantly share code, notes, and snippets.

@hyperfocus1337
Last active February 5, 2025 05:59
Show Gist options
  • Save hyperfocus1337/23b7efff7f8c1dcb0d8c36ac044b98d1 to your computer and use it in GitHub Desktop.
Save hyperfocus1337/23b7efff7f8c1dcb0d8c36ac044b98d1 to your computer and use it in GitHub Desktop.

Revisions

  1. hyperfocus1337 revised this gist Feb 5, 2025. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions frontmatter.js
    Original file line number Diff line number Diff line change
    @@ -11,15 +11,16 @@ tags_slug = tags_array.join("_");
    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 comma-separated, quoted string for the output
    formatted_tags = tags_array.map(tag => `"${tag}"`).join(", ");
    // 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 %>"
    title: <% title_with_spaces %>
    date: <% date %>
    tags:
    <% formatted_tags %>
    identifier: <% identifier %>
    <% "---" %>
    <% tp.file.cursor() %>
  2. hyperfocus1337 created this gist Oct 26, 2024.
    25 changes: 25 additions & 0 deletions frontmatter.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    <%*
    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 comma-separated, quoted string for the output
    formatted_tags = tags_array.map(tag => `"${tag}"`).join(", ");
    // 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() %>