Skip to content

Commit

Permalink
Merge branch 'issue-37'
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaoumov committed Mar 27, 2023
2 parents 6f398fa + d6443ef commit 98d18f4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/links-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,19 @@ export class LinksHandler {
}


getFileByLink(link: string, owningNotePath: string): TFile {
link = link.replace(/#.+/, '');
return this.app.metadataCache.getFirstLinkpathDest(link, owningNotePath);
getFileByLink(link: string, owningNotePath: string, allowInvalidLink: boolean = true): TFile {
link = this.splitLinkToPathAndSection(link).link;
if (allowInvalidLink) {
return this.app.metadataCache.getFirstLinkpathDest(link, owningNotePath);
}
let fullPath = this.getFullPathForLink(link, owningNotePath);
return this.getFileByPath(fullPath);
}


getFileByPath(path: string): TFile {
path = Utils.normalizePathForFile(path);
let files = this.app.vault.getFiles();
let file = files.find(file => Utils.normalizePathForFile(file.path) === path);
return file;
return app.vault.getAbstractFileByPath(path) as TFile;
}


Expand Down Expand Up @@ -220,7 +222,7 @@ export class LinksHandler {
if (this.checkIsCorrectWikiLink(link.original))
continue;

let file = this.getFileByLink(link.link, note.path);
let file = this.getFileByLink(link.link, note.path, false);
if (!file) {
if (!allLinks[note.path])
allLinks[note.path] = [];
Expand Down Expand Up @@ -251,7 +253,7 @@ export class LinksHandler {
if (this.checkIsCorrectWikiEmbed(embed.original))
continue;

let file = this.getFileByLink(embed.link, note.path);
let file = this.getFileByLink(embed.link, note.path, false);
if (!file) {
if (!allEmbeds[note.path])
allEmbeds[note.path] = [];
Expand Down Expand Up @@ -320,7 +322,7 @@ export class LinksHandler {
if (!li.hasSection)
continue;

let file = this.getFileByLink(link.link, note.path);
let file = this.getFileByLink(link.link, note.path, false);
if (file) {
if (file.extension === "pdf" && li.section.startsWith("page=")) {
continue;
Expand Down

0 comments on commit 98d18f4

Please sign in to comment.