Skip to content

Commit

Permalink
Standardize Link in dataview query result list (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
Acylation authored Apr 26, 2024
1 parent 1c0222b commit eed2387
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/lib/datasources/dataview/standardize.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import dayjs from "dayjs";
import type { Link } from "obsidian-dataview";
import {
isRepeatedDataValue,
type DataValue,
type Optional,
} from "src/lib/dataframe/dataframe";
import type { DataValue, Optional } from "src/lib/dataframe/dataframe";

/**
* standardizeValues converts a Dataview data structure of values to the common
Expand All @@ -22,19 +18,24 @@ export function standardizeValues(
return;
}

if (isRepeatedDataValue(value)) {
if (Array.isArray(value)) {
value.map((v) => (typeof v === "object" ? standardizeObject(v) : v));
res[field] = value;
} else if (typeof value === "object") {
if ("path" in value && "display" in value) {
res[field] = (value as Link).toString();
}
if ("ts" in value) {
res[field] = dayjs(value.ts).format("YYYY-MM-DD");
}
res[field] = standardizeObject(value);
} else {
res[field] = value;
}
});

return res;
}

function standardizeObject(value: any) {
if ("path" in value && "display" in value) {
return (value as Link).toString();
}
if ("ts" in value) {
return dayjs(value.ts).format("YYYY-MM-DD");
}
}

0 comments on commit eed2387

Please sign in to comment.