Skip to content

Commit

Permalink
fix: 🐛 less harsh falsey checking on rawValues content
Browse files Browse the repository at this point in the history
Check only for !== undefined wasn't too specific,. Now it checks that the content is truthy
  • Loading branch information
SkepticMystic committed Aug 1, 2021
1 parent c049ad1 commit 2e20b1e
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,25 @@ export function getFieldValues(
settings: BreadcrumbsSettings
) {
// Narrow down the possible types
const rawValues: (string | dvLink)[] =
const rawValues: (string | dvLink | undefined)[] =
[frontmatterCache?.[field]].flat(5) ?? null;

// If there are any values for that field, and they're not undefined (Forget why that can happen...)
if (rawValues.length && rawValues[0] !== undefined) {
superDebug(settings, `${field} of: ${frontmatterCache.file.path}`);
superDebug(settings, { rawValues });

// If there are any values for that field, and they're not undefined
if (rawValues.length && rawValues[0]) {
if (typeof rawValues[0] === "string") {
superDebug(settings, `${field} of: ${frontmatterCache.file.path}`);
superDebug(settings, { rawValues });
return splitAndDrop(rawValues[0]).map((str: string) =>
str.split("/").last()
);
} else {
// Assuming it's a dvLink
superDebug(settings, `${field} of: ${frontmatterCache.file.path}`);
superDebug(settings, { rawValues });
return (rawValues as dvLink[]).map((link: dvLink) =>
link.path.split("/").last()
);
}
} else {
superDebug(settings, `${field} of: ${frontmatterCache.file.path}`);
superDebug(settings, { rawValues });
return [];
}
}
Expand Down

0 comments on commit 2e20b1e

Please sign in to comment.