Skip to content

Commit

Permalink
feat: support unlinked indexes
Browse files Browse the repository at this point in the history
suggested in #9
  • Loading branch information
aviskase committed Nov 17, 2020
1 parent 6550c55 commit 2737940
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -30,6 +30,12 @@ Command will create an index note (check path in settings) with the content:
| -- | -- |
| 2 [[B]]<br><br>2 [[C]]<br><br>1 [[X]] | 2 [[B]]<br>2 [[C]]<br>1 [[X]] |

**Link to files**. When "on" the output file will use wiki-links to files. Disable if you don\'t want to pollute graph with it.

| on | off |
| -- | -- |
| 2 [[B]]<br>2 [[C]]<br>1 [[X]] | 2 B<br>2 C<br>1 X |


## Compatibility
v0.0.1 was developed against Obsidian v0.9.12, but it may work in earlier versions (v0.9.7+).
Expand Down
22 changes: 20 additions & 2 deletions src/main.ts
@@ -1,4 +1,4 @@
import { Plugin, PluginSettingTab, Setting, Vault, normalizePath } from 'obsidian';
import { Plugin, PluginSettingTab, Setting, Vault, normalizePath, TFile } from 'obsidian';

interface IndexNode {
count: number;
Expand Down Expand Up @@ -40,7 +40,7 @@ export default class LinkIndexer extends Plugin {
} else {
uniqueLinks[origin] = {
count: 1,
link: originFile ? `[[${this.app.metadataCache.fileToLinktext(originFile, this.settings.allUsedLinksPath, true)}]]` : `[[${l.link}]]`
link: this.linkToFile(originFile, l.link)
};
}
});
Expand All @@ -56,11 +56,17 @@ export default class LinkIndexer extends Plugin {
this.app.vault.create(this.settings.allUsedLinksPath, content);
}
}

linkToFile(originFile: TFile, fallback: string) {
const rawLink = originFile ? this.app.metadataCache.fileToLinktext(originFile, this.settings.allUsedLinksPath, true) : fallback;
return this.settings.linkToFiles ? `[[${rawLink}]]` : rawLink;
}
}

class LinkIndexerSettings {
allUsedLinksPath = './all_used_links.md';
strictLineBreaks = true;
linkToFiles = true;
}

class LinkIndexerSettingTab extends PluginSettingTab {
Expand Down Expand Up @@ -96,5 +102,17 @@ class LinkIndexerSettingTab extends PluginSettingTab {
await plugin.saveData(plugin.settings);
})
);

new Setting(containerEl)
.setName('Link to files')
.setDesc('When "on" the output file will use wiki-links to files. Disable if you don\'t want to pollute graph with it.')
.addToggle((value) =>
value
.setValue(plugin.settings.linkToFiles)
.onChange(async (value) => {
plugin.settings.linkToFiles = value;
await plugin.saveData(plugin.settings);
})
);
}
}

0 comments on commit 2737940

Please sign in to comment.