Skip to content

Commit

Permalink
fix(List/Matrix View): 🐛 Look for aliases in dv fields, too (fix #256)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 21, 2022
1 parent 238af28 commit baf99aa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
29 changes: 22 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6337,7 +6337,7 @@ function addLinkNotesToGraph(plugin, eligableAlts, frontms, mainG) {
}

function addRegexNotesToGraph(plugin, eligableAlts, frontms, mainG) {
const { app, settings } = plugin;
const { settings } = plugin;
const { userHiers, regexNoteField } = settings;
const fields = getFields(userHiers);
eligableAlts.forEach((altFile) => {
Expand Down Expand Up @@ -28189,19 +28189,34 @@ class MatrixView extends obsidian.ItemView {
return Promise.resolve();
}
getAlt(node) {
var _a;
var _a, _b;
const { altLinkFields, showAllAliases } = this.plugin.settings;
if (altLinkFields.length) {
const file = this.app.metadataCache.getFirstLinkpathDest(node, "");
if (file) {
const metadata = this.app.metadataCache.getFileCache(file);
for (const altField of altLinkFields) {
const value = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.frontmatter) === null || _a === void 0 ? void 0 : _a[altField];
// dv First
const dv = (_a = this.app.plugins.plugins.dataview) === null || _a === void 0 ? void 0 : _a.api;
if (dv) {
const page = dv.page(node);
if (!page)
return null;
for (const alt of altLinkFields) {
const value = page[alt];
const arr = typeof value === "string" ? splitAndTrim(value) : value;
if (value)
return showAllAliases ? arr.join(", ") : arr[0];
}
}
else {
const file = this.app.metadataCache.getFirstLinkpathDest(node, "");
if (file) {
const metadata = this.app.metadataCache.getFileCache(file);
for (const altField of altLinkFields) {
const value = (_b = metadata === null || metadata === void 0 ? void 0 : metadata.frontmatter) === null || _b === void 0 ? void 0 : _b[altField];
const arr = typeof value === "string" ? splitAndTrim(value) : value;
if (value)
return showAllAliases ? arr.join(", ") : arr[0];
}
}
}
}
else
return null;
Expand Down
3 changes: 2 additions & 1 deletion src/AlternativeHierarchies/RegexNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ export function addRegexNotesToGraph(
frontms: dvFrontmatterCache[],
mainG: MultiGraph
) {
const { app, settings } = plugin;
const { settings } = plugin;
const { userHiers, regexNoteField } = settings;
const fields = getFields(userHiers);

eligableAlts.forEach((altFile) => {
const regexNoteFile = altFile.file;
const regexNoteBasename = getDVBasename(regexNoteFile);
Expand Down
27 changes: 20 additions & 7 deletions src/Views/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
MATRIX_VIEW,
TRAIL_ICON,
} from "../constants";
import { getOppDir, getSubInDirs } from "../graphUtils";
import { getOppDir } from "../graphUtils";
import type {
Directions,
internalLinkObj,
Expand All @@ -21,7 +21,6 @@ import type BCPlugin from "../main";
import { refreshIndex } from "../refreshIndex";
import {
getMatrixNeighbours,
getRealnImplied,
linkClass,
splitAndTrim,
} from "../sharedFunctions";
Expand Down Expand Up @@ -73,16 +72,30 @@ export default class MatrixView extends ItemView {
getAlt(node: string): string | null {
const { altLinkFields, showAllAliases } = this.plugin.settings;
if (altLinkFields.length) {
const file = this.app.metadataCache.getFirstLinkpathDest(node, "");
if (file) {
const metadata = this.app.metadataCache.getFileCache(file);
for (const altField of altLinkFields) {
const value = metadata?.frontmatter?.[altField];
// dv First
const dv = this.app.plugins.plugins.dataview?.api;
if (dv) {
const page = dv.page(node);
if (!page) return null;
for (const alt of altLinkFields) {
const value = page[alt] as string;

const arr: string[] =
typeof value === "string" ? splitAndTrim(value) : value;
if (value) return showAllAliases ? arr.join(", ") : arr[0];
}
} else {
const file = this.app.metadataCache.getFirstLinkpathDest(node, "");
if (file) {
const metadata = this.app.metadataCache.getFileCache(file);
for (const altField of altLinkFields) {
const value = metadata?.frontmatter?.[altField];

const arr: string[] =
typeof value === "string" ? splitAndTrim(value) : value;
if (value) return showAllAliases ? arr.join(", ") : arr[0];
}
}
}
} else return null;
}
Expand Down

0 comments on commit baf99aa

Please sign in to comment.