From baf99aa37d90db368a6977870944b2868ac07f1b Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Fri, 21 Jan 2022 22:04:09 +0200 Subject: [PATCH] fix(List/Matrix View): :bug: Look for aliases in dv fields, too (fix #256) --- main.js | 29 ++++++++++++++++++------ src/AlternativeHierarchies/RegexNotes.ts | 3 ++- src/Views/MatrixView.ts | 27 ++++++++++++++++------ 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/main.js b/main.js index 5ccfdeb3..c925e31e 100644 --- a/main.js +++ b/main.js @@ -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) => { @@ -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; diff --git a/src/AlternativeHierarchies/RegexNotes.ts b/src/AlternativeHierarchies/RegexNotes.ts index 91e9f95e..8b95fba9 100644 --- a/src/AlternativeHierarchies/RegexNotes.ts +++ b/src/AlternativeHierarchies/RegexNotes.ts @@ -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); diff --git a/src/Views/MatrixView.ts b/src/Views/MatrixView.ts index 842fadc7..2b725bd4 100644 --- a/src/Views/MatrixView.ts +++ b/src/Views/MatrixView.ts @@ -9,7 +9,7 @@ import { MATRIX_VIEW, TRAIL_ICON, } from "../constants"; -import { getOppDir, getSubInDirs } from "../graphUtils"; +import { getOppDir } from "../graphUtils"; import type { Directions, internalLinkObj, @@ -21,7 +21,6 @@ import type BCPlugin from "../main"; import { refreshIndex } from "../refreshIndex"; import { getMatrixNeighbours, - getRealnImplied, linkClass, splitAndTrim, } from "../sharedFunctions"; @@ -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; }