clean code

This commit is contained in:
IdanL 2024-10-31 23:49:49 +02:00
parent 010442018f
commit fca20b39ba
3 changed files with 9 additions and 49 deletions

View file

@ -19,9 +19,11 @@ Here are some examples of how you might set up FastForwardLink:
- `e=mc2` > `Einstein's special theory of relativity`
- `favorite film` > `bill and ted's bogus journey`
> Press `Ctrl + Alt + R` to quickly create a forwarding link.
### FastForwardLink Plugin Demo
Screenshot or GIF showcasing FastForwardLink in action
![demo](./plugin_demo.gif)
## Features

54
main.ts
View file

@ -28,8 +28,6 @@ export default class RedirectPlugin extends Plugin {
const currentRedirectsFolder =
this.app.vault.getAbstractFileByPath("_forwards");
console.log("currentRedirectsFolder: ", currentRedirectsFolder);
try {
this.redirectsFolder = await this.app.vault.createFolder(
"/_forwards"
@ -39,7 +37,6 @@ export default class RedirectPlugin extends Plugin {
}
this.redirectsFolder = currentRedirectsFolder as TFolder;
console.log("this.redirectsFolder: ", this.redirectsFolder);
}
private async redirect() {
@ -49,16 +46,12 @@ export default class RedirectPlugin extends Plugin {
return;
}
console.log("currentFile", currentFile);
const currentFileContent = (await this.getCurrentFileContent(
currentFile
)) as string;
const targetNoteFile = this.getTargetFile(currentFileContent);
console.log("targetNoteFile", targetNoteFile);
if (!targetNoteFile) {
return;
}
@ -132,66 +125,33 @@ export default class RedirectPlugin extends Plugin {
await this.createRedirectsFolder();
}
// if (redirectingNote.path === `_forwards/${redirectingNote.name}`) {
// new Notice(
// `${redirectingNote.name} is in the _forwards folder.`,
// 2000
// );
// return;
// }
try {
await this.app.vault.copy(
redirectingNoteInFolder = await this.app.vault.copy(
redirectingNote,
`/_forwards/${redirectingNote.name}`
);
// Turn off event handler to avoid opening the target note twice
this.app.workspace.off("file-open", this.redirectRef);
if (this.settings.openInNewTab) {
redirectingNoteInFolder = Object.create(redirectingNote);
redirectingNoteInFolder.path = `_forwards/${redirectingNote.path}`;
// Turn off event handler to avoid opening the target note twice
this.app.workspace.off("file-open", this.redirectRef);
await this.app.workspace.openLinkText(
redirectingNoteInFolder.name,
redirectingNoteInFolder.path
redirectingNoteInFolder.path,
this.settings.openInNewTab,
{ active: this.settings.switchToNewTab }
);
this.app.workspace.on("file-open", this.redirectRef);
}
await this.deleteNote(redirectingNote);
// redirectingNoteInFolder = await this.deleteNote(redirectingNote);
} catch (error) {
console.warn(error);
}
// if (!redirectingNoteInFolder) {
// return;
// }
// return redirectingNoteInFolder;
}
private async deleteNote(orgRedirectingNote: TFile): Promise<TFile | void> {
// let updatedRedirectingNote = orgRedirectingNote;
// if (
// orgRedirectingNote.path === `_forwards/${orgRedirectingNote.name}`
// ) {
// new Notice(
// `${orgRedirectingNote.name} is in the _forwards folder.`,
// 2000
// );
// return;
// }
// if (this.settings.openInNewTab) {
// updatedRedirectingNote = Object.create(orgRedirectingNote);
// updatedRedirectingNote.path = `_forwards/${orgRedirectingNote.path}`;
// }
try {
await this.app.vault.delete(orgRedirectingNote);
} catch (error) {
@ -201,8 +161,6 @@ export default class RedirectPlugin extends Plugin {
);
console.error(error);
}
// return updatedRedirectingNote;
}
async onload() {

BIN
plugin_demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 KiB