Skip to content

Commit

Permalink
feat(plugin): move single text files
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii committed Apr 14, 2024
1 parent 666a7ce commit edb3120
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,24 @@ export default class FileOrganizer extends Plugin {
const fileToMove = await this.createFileFromContent(content);
await this.moveToDefaultAttachmentFolder(file, humanReadableFileName);
await this.appendAttachment(fileToMove, file);
await this.moveAndTagContent(fileToMove, content, humanReadableFileName);
await this.renameTagAndOrganize(fileToMove, content, humanReadableFileName);
}

async handleNonMediaFile(file: TFile, content: string) {
const humanReadableFileName = await this.generateNameFromContent(content);
await this.moveAndTagContent(file, content, humanReadableFileName);
await this.renameTagAndOrganize(file, content, humanReadableFileName);
}

async moveAndTagContent(file: TFile, content: string, newFileName) {
async organizeFile(file: TFile, content: string) {
const destinationFolder = await this.getAIClassifiedFolder(content, file);
await this.moveContent(file, file.basename, destinationFolder);
}

async renameTagAndOrganize(file: TFile, content: string, fileName: string) {
const destinationFolder = await this.getAIClassifiedFolder(content, file);
await this.appendAlias(file, file.basename);
await this.moveContent(file, newFileName, destinationFolder);
await this.appendSimilarTags(content, file);
await this.moveContent(file, fileName, destinationFolder);
}

async createBackup(file: TFile) {
Expand Down Expand Up @@ -515,8 +520,8 @@ export default class FileOrganizer extends Plugin {
},
});
this.addCommand({
id: "organize-file",
name: "Organize current file",
id: "add-to-inbox",
name: "Put in inbox",
callback: async () => {
const activeFile = this.app.workspace.getActiveFile();
if (activeFile) {
Expand All @@ -525,6 +530,18 @@ export default class FileOrganizer extends Plugin {
},
});

this.addCommand({
id: "organize-text-file",
name: "Organize text file",
callback: async () => {
const activeFile = this.app.workspace.getActiveFile();
if (activeFile) {
const fileContent = await this.getTextFromFile(activeFile);
await this.organizeFile(activeFile, fileContent);
}
},
});

this.addCommand({
id: "append-to-similar-file",
name: "Append to similar file",
Expand Down

0 comments on commit edb3120

Please sign in to comment.