Skip to content

Commit

Permalink
add links and tags to ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Dec 4, 2020
1 parent 2d953cc commit 793ce61
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 deletions.
76 changes: 67 additions & 9 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ interface Settings {
directoriesToIgnore: string[];
filesToIgnore: string[];
fileTypesToIgnore: string[];
linksToIgnore: string[];
tagsToIgnore: string[];
}
export default class MyPlugin extends Plugin {
settings: Settings;
Expand All @@ -16,6 +18,8 @@ export default class MyPlugin extends Plugin {
directoriesToIgnore: tempData?.directoriesToIgnore ?? [],
filesToIgnore: tempData?.filesToIgnore ?? [],
fileTypesToIgnore: tempData?.fileTypesToIgnore ?? [],
linksToIgnore: tempData?.linksToIgnore ?? [],
tagsToIgnore: tempData?.tagsToIgnore ?? [],
}

this.addCommand({
Expand Down Expand Up @@ -49,13 +53,14 @@ export default class MyPlugin extends Plugin {
if (this.settings.fileTypesToIgnore.contains(file.extension))
return;

let ignoreBecauseOfDirectory = false;
this.settings.directoriesToIgnore.forEach(value => {
if (file.path.startsWith(value) && value.length != 0)
ignoreBecauseOfDirectory = true;
})
if (ignoreBecauseOfDirectory)
return
if (this.findLinksToIgnore(file))
return;
if (this.findTagsToIgnore(file))
return;
if (this.findDirectoryToIgnore(file))
return;


if (this.settings.filesToIgnore.contains(file.path))
return
if (links.contains(file.path))
Expand All @@ -77,6 +82,37 @@ export default class MyPlugin extends Plugin {
});
this.addSettingTab(new SettingsTab(this.app, this))
}
findDirectoryToIgnore(file: TFile): boolean {
let found = false;
this.settings.directoriesToIgnore.forEach(value => {
if (file.path.startsWith(value) && value.length != 0)
found = true;
})
return found;
}
findLinksToIgnore(file: TFile): boolean {
let found = false;
iterateCacheRefs(this.app.metadataCache.getFileCache(file), cb => {
let link = this.app.metadataCache.getFirstLinkpathDest(cb.link, file.path)?.path
if (!link)
return
if (this.settings.linksToIgnore.contains(link))
found = true;
})
return found;
}
findTagsToIgnore(file: TFile): boolean {
let found = false
let tags = this.app.metadataCache.getFileCache(file).tags
if (!tags)
return false;
tags.forEach(tag => {
if (this.settings.tagsToIgnore.contains(tag.tag.substring(1)))
found = true;
})
return found;
}


onunload() {
console.log('unloading ' + this.manifest.name + " plugin");
Expand Down Expand Up @@ -129,15 +165,37 @@ class SettingsTab extends PluginSettingTab {
this.plugin.settings.filesToIgnore = paths;
this.plugin.saveData(this.plugin.settings);
}));
new Setting(containerEl)
.setName("Links to ignore.")
.setDesc("Ignores files, which contain the given file as link. Add each file path in a new line (with file extension!)")
.addTextArea(cb => cb
.setPlaceholder("Directory/file.md")
.setValue(this.plugin.settings.linksToIgnore.join("\n"))
.onChange((value) => {
let paths = value.trim().split("\n").map(value => formatPath(value, false));
this.plugin.settings.linksToIgnore = paths;
this.plugin.saveData(this.plugin.settings);
}));
new Setting(containerEl)
.setName("Filetypes to ignore.")
.setDesc("Add each filetype separated by comma")
.addTextArea(cb => cb
.setPlaceholder("docx,txt")
.setValue(this.plugin.settings.fileTypesToIgnore.join(","))
.onChange((value) => {
let paths = value.trim().split(",");
this.plugin.settings.fileTypesToIgnore = paths;
let extensions = value.trim().split(",");
this.plugin.settings.fileTypesToIgnore = extensions;
this.plugin.saveData(this.plugin.settings);
}));
new Setting(containerEl)
.setName("Tags to ignore.")
.setDesc("Ignore files, which contain the given tag. Add each tag separated by comma (without `#`)")
.addTextArea(cb => cb
.setPlaceholder("todo,unfinished")
.setValue(this.plugin.settings.tagsToIgnore.join(","))
.onChange((value) => {
let tags = value.trim().split(",");
this.plugin.settings.tagsToIgnore = tags;
this.plugin.saveData(this.plugin.settings);
}));

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "find-unlinked-files",
"name": "Find unlinked files",
"version": "0.2.1",
"version": "0.2.2",
"description": "Find files that are not linked anywhere and would otherwise be lost in your vault. In other words: files with no backlinks",
"author": "Vinzent",
"authorUrl": "https://github.com/Vinzent03",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "find-unlinked-files",
"version": "0.2.1",
"version": "0.2.2",
"description": "Find files that are not linked anywhere and would otherwise be lost",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 793ce61

Please sign in to comment.