mirror of
https://github.com/idanlib/ObsidianFastForwardLinkPlugin.git
synced 2026-07-22 11:30:28 +00:00
clean code
This commit is contained in:
parent
010442018f
commit
fca20b39ba
3 changed files with 9 additions and 49 deletions
|
|
@ -19,9 +19,11 @@ Here are some examples of how you might set up FastForwardLink:
|
||||||
- `e=mc2` > `Einstein's special theory of relativity`
|
- `e=mc2` > `Einstein's special theory of relativity`
|
||||||
- `favorite film` > `bill and ted's bogus journey`
|
- `favorite film` > `bill and ted's bogus journey`
|
||||||
|
|
||||||
|
> Press `Ctrl + Alt + R` to quickly create a forwarding link.
|
||||||
|
|
||||||
### FastForwardLink Plugin Demo
|
### FastForwardLink Plugin Demo
|
||||||
|
|
||||||
Screenshot or GIF showcasing FastForwardLink in action
|

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