Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/ResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ const ResultRow = ({
<a
className={"rm-page-ref"}
data-link-title={getPageTitleByPageUid(uid) || ""}
href={getRoamUrl(uid)}
href={(r[`${key}-url`] as string) || getRoamUrl(uid)}
onMouseDown={(e) => {
if (e.shiftKey) {
openBlockInSidebar(uid);
Expand Down
14 changes: 13 additions & 1 deletion src/utils/predefinedSelections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ const formatDate = ({
const flatten = (blocks: PullBlock[] = []): PullBlock[] =>
blocks.flatMap((b) => [b, ...flatten(b[":block/children"])]);

const isValidUrl = (value: string): boolean => {
try {
new URL(value);
return true;
} catch {
return false;
}
};

const getBlockAttribute = (key: string, r: PullBlock) => {
const blocks = flatten(
window.roamAlphaAPI.pull(
Expand All @@ -127,9 +136,12 @@ const getBlockAttribute = (key: string, r: PullBlock) => {
const block = blocks.find((blk) =>
(blk[":block/string"] || "").startsWith(key + "::")
);
const value = (block?.[":block/string"] || "").slice(key.length + 2).trim();

return {
"": (block?.[":block/string"] || "").slice(key.length + 2).trim(),
"": value,
"-uid": block?.[":block/uid"] || "",
...(isValidUrl(value) && { "-url": value }),
};
};

Expand Down
Loading