Skip to content

Commit

Permalink
fix(CreateIndex): 🐛 Check if currFile is null
Browse files Browse the repository at this point in the history
This occurs when showAliasesInIndex is enabled, but the link is unresolved. So getFileCache is checking for the cache of null
  • Loading branch information
SkepticMystic committed Sep 7, 2021
1 parent 60e81b0 commit c1c8f17
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
23 changes: 13 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26165,6 +26165,7 @@ class MatrixView extends obsidian.ItemView {
reversed.forEach((path) => path.shift());
const indent = " ";
const visited = {};
const activeFile = this.app.workspace.getActiveFile();
reversed.forEach((path) => {
var _a, _b, _c, _d;
for (let depth = 0; depth < path.length; depth++) {
Expand All @@ -26180,16 +26181,18 @@ class MatrixView extends obsidian.ItemView {
index += currNode;
index += settings.wikilinkIndex ? "]]" : "";
if (settings.aliasesInIndex) {
const currFile = this.app.metadataCache.getFirstLinkpathDest(currNode, this.app.workspace.getActiveFile().path);
const cache = this.app.metadataCache.getFileCache(currFile);
const alias = (_b = (_a = cache === null || cache === void 0 ? void 0 : cache.frontmatter) === null || _a === void 0 ? void 0 : _a.alias) !== null && _b !== void 0 ? _b : [];
const aliases = (_d = (_c = cache === null || cache === void 0 ? void 0 : cache.frontmatter) === null || _c === void 0 ? void 0 : _c.aliases) !== null && _d !== void 0 ? _d : [];
const allAliases = [
...[alias].flat(3),
...[aliases].flat(3),
];
if (allAliases.length) {
index += ` (${allAliases.join(", ")})`;
const currFile = this.app.metadataCache.getFirstLinkpathDest(currNode, activeFile.path);
if (currFile !== null) {
const cache = this.app.metadataCache.getFileCache(currFile);
const alias = (_b = (_a = cache === null || cache === void 0 ? void 0 : cache.frontmatter) === null || _a === void 0 ? void 0 : _a.alias) !== null && _b !== void 0 ? _b : [];
const aliases = (_d = (_c = cache === null || cache === void 0 ? void 0 : cache.frontmatter) === null || _c === void 0 ? void 0 : _c.aliases) !== null && _d !== void 0 ? _d : [];
const allAliases = [
...[alias].flat(3),
...[aliases].flat(3),
];
if (allAliases.length) {
index += ` (${allAliases.join(", ")})`;
}
}
}
index += "\n";
Expand Down
26 changes: 16 additions & 10 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ export default class MatrixView extends ItemView {

const indent = " ";
const visited: { [node: string]: number[] } = {};

const activeFile = this.app.workspace.getActiveFile();
reversed.forEach((path) => {
for (let depth = 0; depth < path.length; depth++) {
const currNode = path[depth];
Expand All @@ -212,21 +214,25 @@ export default class MatrixView extends ItemView {
index += settings.wikilinkIndex ? "]]" : "";

if (settings.aliasesInIndex) {

const currFile = this.app.metadataCache.getFirstLinkpathDest(
currNode,
this.app.workspace.getActiveFile().path
activeFile.path
);
const cache = this.app.metadataCache.getFileCache(currFile);

const alias = cache?.frontmatter?.alias ?? [];
const aliases = cache?.frontmatter?.aliases ?? [];
if (currFile !== null) {
const cache = this.app.metadataCache.getFileCache(currFile);

const alias = cache?.frontmatter?.alias ?? [];
const aliases = cache?.frontmatter?.aliases ?? [];

const allAliases: string[] = [
...[alias].flat(3),
...[aliases].flat(3),
];
if (allAliases.length) {
index += ` (${allAliases.join(", ")})`;
const allAliases: string[] = [
...[alias].flat(3),
...[aliases].flat(3),
];
if (allAliases.length) {
index += ` (${allAliases.join(", ")})`;
}
}
}

Expand Down

0 comments on commit c1c8f17

Please sign in to comment.