Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: Add Support for File Extensions in Rename Patterns #100

Open
danieldanilov opened this issue Nov 15, 2024 · 1 comment
Open

Issue: Add Support for File Extensions in Rename Patterns #100

danieldanilov opened this issue Nov 15, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@danieldanilov
Copy link

Context

I use the Paste Image Rename plugin to rename files dynamically based on templates. My workflow requires appending the file extension (e.g., .png, .jpg) to the renamed file title automatically, but the current template system does not support this.

Issue

Without access to the file extension in the rename pattern, I cannot dynamically include extensions in file titles. This limits my ability to automate workflows effectively, as other plugins (like Auto Note Mover) rely on title-based regex matching to sort files by type. Manually appending extensions to titles defeats the purpose of automation.

Request

Please add a {{fileExt}} variable (or equivalent) to the rename pattern system, allowing the file extension to be dynamically appended to the title. For example:
• Pattern: {{fileName}}-{{DATE:YYYYMMDD}}.{{fileExt}}
• Output: NoteTitle-20241115.png

Alternatively, consider a setting to toggle the inclusion of file extensions in rename patterns.

Conclusion

This feature would:
1. Enable seamless integration with file organization workflows (e.g., Auto Note Mover).
2. Enhance automation capabilities by avoiding manual file renaming.
3. Expand the plugin’s flexibility for advanced use cases, saving users time and effort.

Thank you for creating such a powerful tool. Let me know if more details would help!

@danieldanilov danieldanilov added the enhancement New feature or request label Nov 15, 2024
@danieldanilov
Copy link
Author

I briefly talked this through with ChatGPT:

To enhance the Paste Image Rename plugin by incorporating the file extension into the rename pattern, consider the following approach:

  1. Introduce a {{fileExt}} Variable:
    Modify the plugin to recognize a new {{fileExt}} variable within the imageNamePattern. This variable would represent the file’s extension, enabling users to include it directly in their rename templates.

  2. Update the generateNewName Function:
    In the generateNewName function, extract the file extension and assign it to the fileExt variable. Then, pass this variable to the renderTemplate function alongside existing variables like fileName and imageNameKey.

  3. Adjust the renderTemplate Function:
    Enhance the renderTemplate function to process the {{fileExt}} variable. This adjustment allows the function to replace {{fileExt}} in the pattern with the actual file extension during the renaming process.

  4. Update Documentation:
    Reflect these changes in the plugin’s documentation, providing users with clear instructions on how to utilize the new {{fileExt}} variable in their rename patterns.

Example Implementation:

In the generateNewName function, after determining the fileName and other variables, add:

const fileExt = file.extension;

Then, pass fileExt to the renderTemplate function:

const stem = renderTemplate(
    this.settings.imageNamePattern,
    {
        imageNameKey,
        fileName: activeFile.basename,
        dirName: activeFile.parent.name,
        firstHeading,
        fileExt, // Add this line
    },
    frontmatter
);

In the renderTemplate function, ensure it processes the fileExt variable appropriately.

By implementing these changes, users can dynamically include file extensions in their rename patterns, enhancing the plugin’s flexibility and integration with other tools.

Note: This approach assumes familiarity with the plugin’s codebase and JavaScript development within the Obsidian plugin framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant