dy-sh / obsidian-consistent-attachments-and-links

Obsidian plugin. Move note with attachments.
MIT License
202 stars 20 forks source link

Consistent Attachments and Links

The plugin for Obsidian allows you to reorganize your vault to make it more consistent. Next, the plugin will automatically maintain the consistency of your library.

⚠️⚠️⚠️ Be sure to backup your library before using the plugin for the first time! ⚠️⚠️⚠️

What's the idea

The idea is to have all links between notes and attachments in strict accordance with the markdown format and support their relative paths. This is useful when you want to open a note in another program that does not know where your vault folder is, or for example you want to publish and read your notes on GitHub or another site that allows you to upload markdown files and you need compatibility.

Ideally, all attachments should be located in the note folder or its subfolders. It is not necessary, but in this case, you can easily export a note to a separate folder outside of your vault, knowing that all its attachments are with it. By deleting a note, you will know for sure that you will not delete the attachments you need or leave unnecessary garbage in your library.

If you store attachments in a folder with a note or its subfolders, the plugin will automatically move\delete attachments when you move or delete a note.

Disclaimer

Please backup your library before using this plugin! Once converted links cannot be converted back.

To use this plugin, you will have to give up all the proprietary things that Obsidian uses in the link format.

Obsidian has a very clever file link search, but this can be a problem for you if you want your notes to be compatible with other programs. This is the main point of the plugin.

If you still want to have link compatibility with some Obsidian features, write a feature request to the github repository of this plugin.

How to configure Obsidian

Required Obsidian settings for the plugin to work properly:

Recommended additional settings (not required for the plugin to work):

How to check the consistency of the library

Run "Check Vault Consistency" command and see the report.

How to achieve consistency of an existing library

It is very important to make a backup of the entire vault folder before these steps.

Specify "Attachments subfolder" name in the plugin settings.

Run the commands in the following order to reorganize vault:

Or just run "Reorganize Vault" command, then rename all attachments using Unique attachments (optional)

You can look at the console log to make sure everything worked out without errors. Errors can point to broken links (paths to files that no longer exist).

How this plugin helps maintain consistency

When you move a note in Obsidian, the plugin checks if attachments need to be moved and links updated. If attachments are in a folder with a note or subfolders, then the plugin moves the attachments along with the note.

It does this safely, making sure not to move attachments that are referenced by other notes. If you move a note with attachments that are used in other notes, the plugin automatically creates a copy of this files and redirects the moved note to them.

If you move a note to a folder where there are already attachments with the same names, the plugin can work in two modes, depending on "Delete Duplicate Attachments on Note Move" setting:

When deleting a note, the plugin can delete all attachments that are no longer in use. This option can be disabled.

The plugin is also able to automatically delete empty folders that result from moving files, as well as update the text of links when renaming notes (optionally).

Commands

The plugin has the following commands that you can call:

Check Vault Consistency

Check if there are vault consistency problems and print the report. The report will contain:

Reorganize Vault

Runs the following commands one by one:

This is the fastest way to clean up your library.

Replace All Wiki Links with Markdown Links

Searches for all wiki links in notes and converts them into regular markdown links.

Example:
[[readme]]
will turn into this:
[readme](readme.md)

Convert All Embed Paths to Relative

Searches for all embeds in notes and converts their paths to relative format.

Example:
![](title.png)
will turn into this:
![](../attachments/title.png)

This is one of the most important steps on the road to consistency, ensuring that all embed links now point to the correct files accurately.

Convert All Link Paths to Relative

Does the same as "Convert all embed paths to relative" for links.

Example:
[](readme.md)
will turn into this:
[](../readme.md)

Collect All Attachments

The plugin finds all the notes and moves all attachments in the note folder. This is useful if you are not sure if all attachments are in your notes folders and you want to clean up your library. In the "Attachments subfolder" plugin settings parameter, you can specify how the subfolder named in order to move attachments to it. If you leave this field blank, then attachments will be moved directly to the folder with the note, without subfolders. At any time, we can change this name and reorganize the folder structure in one click, the attachments will be moved to new folders.

Delete Empty Folders

Removes all empty folders in your library.