Skip to content

Commit

Permalink
fix: 🐛 Add debug logs to getFields and getFrontmatter functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Aug 1, 2021
1 parent 1135617 commit 193eb46
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import type { Graph } from "graphlib";
import * as graphlib from "graphlib";
import { parseTypedLink } from "juggl-api";
import type {
App,
CachedMetadata,
FrontMatterCache,
TFile,
WorkspaceLeaf,
} from "obsidian";
import type { App, FrontMatterCache, TFile, WorkspaceLeaf } from "obsidian";
import { dropHeaderOrAlias, splitLinksRegex } from "src/constants";
import type {
BreadcrumbsSettings,
Expand Down Expand Up @@ -79,6 +73,7 @@ export function getObsMetadataCache(
files.forEach((file) => {
const obs: FrontMatterCache =
app.metadataCache.getFileCache(file).frontmatter;
superDebug(settings, { obs });
if (obs) {
fileFrontmatterArr.push({ file, ...obs });
} else {
Expand Down Expand Up @@ -163,22 +158,26 @@ export async function getJugglLinks(

export function getFieldValues(
frontmatterCache: dvFrontmatterCache,
field: string
field: string,
settings: BreadcrumbsSettings
) {
const rawValues: (string | dvLink)[] =
[frontmatterCache?.[field]].flat(5) ?? null;

if (rawValues.length && rawValues[0] !== undefined) {
if (typeof rawValues[0] === "string") {
superDebug(settings, { rawValues });
return splitAndDrop(rawValues[0]).map((str: string) =>
str.split("/").last()
);
} else {
superDebug(settings, { rawValues });
return (rawValues as dvLink[]).map((link: dvLink) =>
link.path.split("/").last()
);
}
} else {
superDebug(settings, { rawValues });
return [];
}
}
Expand Down Expand Up @@ -207,13 +206,19 @@ export async function getNeighbourObjArr(
(fileFrontmatter) => {
let [parents, siblings, children] = [
parentFields
.map((parentField) => getFieldValues(fileFrontmatter, parentField))
.map((parentField) =>
getFieldValues(fileFrontmatter, parentField, plugin.settings)
)
.flat(3),
siblingFields
.map((siblingField) => getFieldValues(fileFrontmatter, siblingField))
.map((siblingField) =>
getFieldValues(fileFrontmatter, siblingField, plugin.settings)
)
.flat(3),
childFields
.map((childField) => getFieldValues(fileFrontmatter, childField))
.map((childField) =>
getFieldValues(fileFrontmatter, childField, plugin.settings)
)
.flat(3),
];

Expand Down

0 comments on commit 193eb46

Please sign in to comment.