obsidian-custom-attachment-location icon indicating copy to clipboard operation
obsidian-custom-attachment-location copied to clipboard

Support date var template(moment.js) in folder path & image name

Open Harrd opened this issue 8 months ago • 0 comments

Support Date Template Variables in Path by Changing getAttachmentFolderPath/getPastedImageFileName Behavior

For example: /dir1/${date:YYYY}/${date:MM}/${filename} will be transformed to /dir1/2024/03/target_file/

Implementation Details:

  • Use a regex pattern to match date variables (vars starting with ${date:} / ${filename}).

File Attachment Folder Behavior:

  • If the file already has an attachment folder: Use the earliest folder that matches the regex.
  • If the file has no attachment folder (no folder matches the regex): Create a new one using the current date and time.

Important Notes:

  • getAttachmentFolderPath will become asynchronous, so adjust the invocation timing in the handlePaste event accordingly.
  • Only support fixed digit formats in ${date:} like YYYY, MM, DD, Q. (${date:YYYY} will compile to d[4] regex for matching earliest attachment folder)

conf example: image

Harrd avatar Jun 07 '24 15:06 Harrd