Skip to content

Commit 1e232ca

Browse files
authored
handle attribute urls (#58)
1 parent 6326417 commit 1e232ca

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

apps/roam/src/components/ResultsView/views/ResultsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ const ResultRow = ({
306306
<a
307307
className={"rm-page-ref"}
308308
data-link-title={getPageTitleByPageUid(uid) || ""}
309-
href={getRoamUrl(uid)}
309+
href={(r[`${key}-url`] as string) || getRoamUrl(uid)}
310310
onMouseDown={(e) => {
311311
if (e.shiftKey) {
312312
openBlockInSidebar(uid);

apps/roam/src/utils/predefinedSelections.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ const formatDate = ({
118118
const flatten = (blocks: PullBlock[] = []): PullBlock[] =>
119119
blocks.flatMap((b) => [b, ...flatten(b[":block/children"])]);
120120

121+
const isValidUrl = (value: string): boolean => {
122+
try {
123+
new URL(value);
124+
return true;
125+
} catch {
126+
return false;
127+
}
128+
};
129+
121130
const getBlockAttribute = (key: string, r: PullBlock) => {
122131
const blocks = flatten(
123132
window.roamAlphaAPI.pull(
@@ -128,9 +137,12 @@ const getBlockAttribute = (key: string, r: PullBlock) => {
128137
const block = blocks.find((blk) =>
129138
(blk[":block/string"] || "").startsWith(key + "::"),
130139
);
140+
const value = (block?.[":block/string"] || "").slice(key.length + 2).trim();
141+
131142
return {
132-
"": (block?.[":block/string"] || "").slice(key.length + 2).trim(),
143+
"": value,
133144
"-uid": block?.[":block/uid"] || "",
145+
...(isValidUrl(value) && { "-url": value }),
134146
};
135147
};
136148

0 commit comments

Comments
 (0)