Skip to content

Commit

Permalink
fix: aggregate header and block links
Browse files Browse the repository at this point in the history
fixes #6
  • Loading branch information
aviskase committed Nov 18, 2020
1 parent fb1ed70 commit 2d9e182
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
};
}
});
Expand Down

0 comments on commit 2d9e182

Please sign in to comment.