generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* moved source code in src * added sentence case * refactored tag adding * canvases now ignore themselves * preparation for later
- Loading branch information
1 parent
c90958c
commit 2c66624
Showing
5 changed files
with
52 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Plugin, TFile, TFolder } from 'obsidian'; | ||
import { EnterTagsModal } from './EnterTagsModal'; | ||
|
||
export default class TagManyPlugin extends Plugin { | ||
settings: TagManyPlugin; | ||
|
||
async onload() { | ||
this.registerEvent( | ||
this.app.workspace.on("file-menu", (menu, folder) => { | ||
if (!(folder instanceof TFolder)) return; | ||
menu.addItem((item) => { | ||
item | ||
.setTitle("Tag all notes in this folder") | ||
.setIcon("tags") | ||
.onClick(async () => { | ||
new EnterTagsModal(this.app, async (tags, includeSubfolders) => { | ||
if (tags) { | ||
const tagArray = tags.split(","); | ||
await this.addTagsToNotes(tagArray, folder, includeSubfolders); | ||
} | ||
}).open(); | ||
}); | ||
}); | ||
}) | ||
); | ||
} | ||
|
||
onunload(): void { | ||
|
||
} | ||
|
||
async addTagsToNotes(tags: string[], folder: TFolder, includeSubfolders: boolean, counter: number[] = [0]) { | ||
for (const note of folder.children) { | ||
if (note instanceof TFolder) { | ||
if (includeSubfolders) await this.addTagsToNotes(tags, note, true, counter); | ||
continue; | ||
} | ||
|
||
this.app.fileManager.processFrontMatter(note as TFile, (frontmatter) => { | ||
frontmatter.tags = [...new Set([...frontmatter.tags, ...tags])]; | ||
}) | ||
|
||
counter[0]++; | ||
} | ||
} | ||
} | ||
|