antoniotejada / obsidian-edit-history

Obsidian Edit History Plugin, automatically save all the edit history of a note, browse and restore previous versions
GNU Affero General Public License v3.0
55 stars 1 forks source link

Allow keeping history only for specified files #1

Closed tofu-connected closed 1 year ago

tofu-connected commented 1 year ago

If there are a a lot of different kinds of files in the project, one might want to keep history only for some files and don't clutter the the vault with unnecessary history files.

antoniotejada commented 1 year ago

So there's something that can help you there, there's already a "whitelist extension" in settings:

image

Even if the files that you want to keep history for have the same extension as the ones you don't, you can still use the whitelist: the trick is that the whitelist not only works for extensions but for any substring the file ends with (suffix): the code will keep the history file if the filename ends with any of those words and there's no reason why you cannot put a whole filename there:

https://github.com/antoniotejada/obsidian-edit-history/blob/6d55e99c4ff098d8a9ec2e5dbe5d56420278a7f4/releases/0.1.0/main.js#L4461

        // Keep an edit history file for all files if there are no extensions,
        // otherwise just for the extensions that match
        if (this.extensionWhitelist.length == 0) {
            return true;
        } else {
            const filename = file.name.toLowerCase();
            for (let ext of this.extensionWhitelist) {
                if (filename.endsWith(ext)) {
                    return true;
                }
            }
        }
        return false;

Eg if you have "badfile.md" and "goodfile.md" and you want to keep the history for "goodfile.md", just remove ".md" from the whitelist and put "goodfile.md" instead (or even "odfile.md"). This will even work if the filename you want to put in the whitelist has a space in the middle since the list separator is the comma (but obviously won't if you want to put a filename with a comma in it).

Closing, since this seems to solve your issue.