From 2d9e18211e3089499d64d98df7c8df7c38c9ebf2 Mon Sep 17 00:00:00 2001 From: Yuliya Bagriy Date: Tue, 17 Nov 2020 19:06:23 -0500 Subject: [PATCH] fix: aggregate header and block links fixes #6 --- package.json | 4 ++-- src/main.ts | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index bd52bb8..b9697fc 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,9 @@ "@rollup/plugin-commonjs": "^15.1.0", "@rollup/plugin-node-resolve": "^9.0.0", "@rollup/plugin-typescript": "^6.0.0", - "@types/node": "^14.14.2", + "@types/node": "^14.14.8", "obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master", - "rollup": "^2.32.1", + "rollup": "^2.33.2", "standard-version": "^9.0.0", "tslib": "^2.0.3", "typescript": "^4.0.3" diff --git a/src/main.ts b/src/main.ts index 4af6005..e421299 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { Plugin, PluginSettingTab, Setting, Vault, normalizePath, TFile } from 'obsidian'; +import { Plugin, PluginSettingTab, Setting, Vault, normalizePath, TFile, getLinkpath } from 'obsidian'; interface IndexNode { count: number; @@ -33,14 +33,15 @@ export default class LinkIndexer extends Plugin { files.forEach((f) => { const links = this.app.metadataCache.getFileCache(f).links; links?.forEach((l) => { - const originFile = this.app.metadataCache.getFirstLinkpathDest(l.link, f.path); - const origin = originFile ? originFile.path : l.link; + const link = getLinkpath(l.link); + const originFile = this.app.metadataCache.getFirstLinkpathDest(link, f.path); + const origin = originFile ? originFile.path : link; if (uniqueLinks[origin]) { uniqueLinks[origin].count += 1; } else { uniqueLinks[origin] = { count: 1, - link: this.linkToFile(originFile, l.link) + link: this.linkToFile(originFile, link) }; } });