Skip to content

Commit

Permalink
Submission review (#5)
Browse files Browse the repository at this point in the history
* moved source code in src

* added sentence case

* refactored tag adding

* canvases now ignore themselves

* preparation for later
  • Loading branch information
joshua-martius committed Jul 29, 2023
1 parent c90958c commit 2c66624
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 66 deletions.
2 changes: 1 addition & 1 deletion esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["main.ts"],
entryPoints: ["src/main.ts"],
bundle: true,
external: [
"obsidian",
Expand Down
61 changes: 0 additions & 61 deletions main.ts

This file was deleted.

4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "tag-many",
"name": "TagMany",
"version": "0.2.4",
"version": "0.2.5",
"minAppVersion": "0.15.0",
"description": "This plugin allows you to add the same tag(s) to multiple notes in a folder (optionally including subfolders) at once.",
"description": "Add the same tag(s) to multiple notes in a folder (optionally including subfolders) at once.",
"author": "Joshua Martius",
"authorUrl": "https://fngt.nl/joshua",
"isDesktopOnly": true
Expand Down
4 changes: 2 additions & 2 deletions EnterTagsModal.ts → src/EnterTagsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class EnterTagsModal extends Modal {
onOpen() {
const { contentEl } = this;

contentEl.createEl("h2", { text: "What tags do you want to add to the Notes?" });
contentEl.createEl("h2", { text: "What tags do you want to add to the notes?" });

new Setting(contentEl)
.setName("Tags (separate with commas)")
Expand All @@ -23,7 +23,7 @@ export class EnterTagsModal extends Modal {
}));

new Setting(contentEl)
.setName("Include Subfolders?")
.setName("Include subfolders?")
.addToggle((toggle) =>
toggle.onChange((value) => {
this.includeSubfolders = value
Expand Down
47 changes: 47 additions & 0 deletions src/main.ts
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]++;
}
}
}

0 comments on commit 2c66624

Please sign in to comment.