Skip to content

Commit e2e82fb

Browse files
committed
(feat) include links in vulpea-note
Following discussion #106
1 parent a1cdaf4 commit e2e82fb

File tree

6 files changed

+91
-24
lines changed

6 files changed

+91
-24
lines changed

CHANGELOG.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
property.
2727
- New function to select on arbitrary list of notes as opposed to relying on
2828
filter - =vulpea-select-from=.
29+
- [[https://github.com/d12frosted/vulpea/discussions/106][vulpea#106]] Include links in =vulpea-note=.
2930

3031
** v0.2.0
3132

README.org

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ slots/fields:
148148
- =vulpea-note-primary-title= - primary title of the note (present only when
149149
=title= is an alias);
150150
- =vulpea-note-aliases= - aliases of the note;
151+
- =vulpea-note-links= - list of links, each link being represented as =cons= of
152+
type and link;
151153
- =vulpea-note-tags= - tags of the note;
152154
- =vulpea-note-meta= - associative list of [[#metadata][metadata]], where key is a string and
153155
the value is a list of strings. There are also two utilities to access/query

test/vulpea-db-test.el

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
(cons "FILE" (expand-file-name "same-name-2.org" org-roam-directory))
172172
(cons "PRIORITY" "B"))))))
173173

174-
(it "includes meta"
174+
(it "includes meta and links"
175175
(expect (vulpea-db-query
176176
(lambda (n)
177177
(seq-contains-p
@@ -185,6 +185,9 @@
185185
:tags nil
186186
:level 0
187187
:id "05907606-f836-45bf-bd36-a8444308eddd"
188+
:links '(("https" . "https://en.wikipedia.org/wiki/Frappato")
189+
("id" . "444f94d7-61e0-4b7c-bb7e-100814c6b4bb")
190+
("id" . "5093fc4e-8c63-4e60-a1da-83fc7ecd5db7"))
188191
:properties (list
189192
(cons "CATEGORY" "with-meta")
190193
(cons "ID" "05907606-f836-45bf-bd36-a8444308eddd")
@@ -266,7 +269,7 @@
266269
(cons "PRIORITY" "B")
267270
(cons "ITEM" "Big note sub-sub-heading")))))
268271

269-
(it "includes meta in response"
272+
(it "includes meta and links in response"
270273
(expect (vulpea-db-get-by-id "05907606-f836-45bf-bd36-a8444308eddd")
271274
:to-equal
272275
(make-vulpea-note
@@ -275,6 +278,9 @@
275278
:tags nil
276279
:level 0
277280
:id "05907606-f836-45bf-bd36-a8444308eddd"
281+
:links '(("https" . "https://en.wikipedia.org/wiki/Frappato")
282+
("id" . "444f94d7-61e0-4b7c-bb7e-100814c6b4bb")
283+
("id" . "5093fc4e-8c63-4e60-a1da-83fc7ecd5db7"))
278284
:properties (list
279285
(cons "CATEGORY" "with-meta")
280286
(cons "ID" "05907606-f836-45bf-bd36-a8444308eddd")
@@ -413,6 +419,9 @@
413419
:tags nil
414420
:level 0
415421
:id "05907606-f836-45bf-bd36-a8444308eddd"
422+
:links '(("https" . "https://en.wikipedia.org/wiki/Frappato")
423+
("id" . "444f94d7-61e0-4b7c-bb7e-100814c6b4bb")
424+
("id" . "5093fc4e-8c63-4e60-a1da-83fc7ecd5db7"))
416425
:properties (list
417426
(cons "CATEGORY" "with-meta")
418427
(cons "ID" "05907606-f836-45bf-bd36-a8444308eddd")
@@ -434,6 +443,9 @@
434443
:tags nil
435444
:level 0
436445
:id "05907606-f836-45bf-bd36-a8444308eddd"
446+
:links '(("https" . "https://en.wikipedia.org/wiki/Frappato")
447+
("id" . "444f94d7-61e0-4b7c-bb7e-100814c6b4bb")
448+
("id" . "5093fc4e-8c63-4e60-a1da-83fc7ecd5db7"))
437449
:properties (list
438450
(cons "CATEGORY" "with-meta")
439451
(cons "ID" "05907606-f836-45bf-bd36-a8444308eddd")

test/vulpea-test.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@
284284
:tags '("tag1" "tag2")
285285
:level 0
286286
:id (vulpea-note-id note)
287+
:links '(("https" . "https://d12frosted.io"))
287288
:properties (list
288289
(cons "CATEGORY" "prefix-aglianico")
289290
(cons "MY_TAG" "super-tag")

vulpea-db.el

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ returned."
8787
file,
8888
title,
8989
\"level\",
90-
'(' || group_concat(tags, ' ') || ')' as tags,
90+
tags,
9191
aliases,
92+
'(' || group_concat(links, ' ') || ')' as links,
9293
properties,
9394
meta
9495
from
@@ -98,33 +99,61 @@ from
9899
file,
99100
title,
100101
\"level\",
101-
tags,
102-
'(' || group_concat(aliases, ' ') || ')' as aliases,
102+
'(' || group_concat(tags,
103+
' ') || ')' as tags,
104+
aliases,
105+
links,
103106
properties,
104107
meta
105108
from
106109
(
107110
select
108-
nodes.id as id,
109-
nodes.file as file,
110-
nodes.title as title,
111-
nodes.\"level\" as \"level\",
112-
tags.tag as tags,
113-
aliases.alias as aliases,
114-
nodes.properties as properties,
115-
'(' || group_concat('(' || meta.prop
111+
id,
112+
file,
113+
title,
114+
\"level\",
115+
tags,
116+
'(' || group_concat(aliases,
117+
' ') || ')' as aliases,
118+
links,
119+
properties,
120+
meta
121+
from
122+
(
123+
select
124+
nodes.id as id,
125+
nodes.file as file,
126+
nodes.title as title,
127+
nodes.\"level\" as \"level\",
128+
tags.tag as tags,
129+
aliases.alias as aliases,
130+
'(' || links.\"type\" || ' ' || links.dest || ')' as links,
131+
nodes.properties as properties,
132+
'(' || group_concat('(' || meta.prop
116133
|| ' '
117134
|| meta.value
118135
|| ')',
119-
' ')
136+
' ')
120137
|| ')' as meta
121-
from nodes
122-
left join tags on tags.node_id = nodes.id
123-
left join aliases on aliases.node_id = nodes.id
124-
left join meta on meta.node_id = nodes.id
125-
group by nodes.id, tags.tag, aliases.alias )
126-
group by id, tags )
127-
group by id"))
138+
from nodes
139+
left join tags on tags.node_id = nodes.id
140+
left join aliases on aliases.node_id = nodes.id
141+
left join meta on meta.node_id = nodes.id
142+
left join links on links.\"source\" = nodes.id
143+
group by
144+
nodes.id,
145+
tags.tag,
146+
aliases.alias,
147+
links.dest)
148+
group by
149+
id,
150+
tags,
151+
links)
152+
group by
153+
id,
154+
links)
155+
group by
156+
id"))
128157
notes)
129158
(dolist (row rows notes)
130159
(let ((id (nth 0 row))
@@ -133,8 +162,9 @@ group by id"))
133162
(level (nth 3 row))
134163
(tags (nth 4 row))
135164
(aliases (nth 5 row))
136-
(properties (nth 6 row))
137-
(meta (nth 7 row)))
165+
(links (nth 6 row))
166+
(properties (nth 7 row))
167+
(meta (nth 8 row)))
138168
(dolist (name (cons title aliases))
139169
(let ((note (make-vulpea-note
140170
:path file
@@ -146,6 +176,9 @@ group by id"))
146176
:aliases aliases
147177
:id id
148178
:level level
179+
:links (seq-uniq (seq-map
180+
#'vulpea-db--parse-link-pair
181+
links))
149182
:properties properties
150183
:meta (seq-map
151184
(lambda (row)
@@ -221,17 +254,34 @@ If the FILE is relative, it is considered to be relative to
221254
[:select [prop value]
222255
:from meta
223256
:where (= node-id $s1)]
224-
id))))
257+
id)))
258+
(links (seq-map
259+
#'vulpea-db--parse-link-pair
260+
(org-roam-db-query
261+
[:select [type dest]
262+
:from links
263+
:where (and (= source $s1))]
264+
id))))
225265
(make-vulpea-note
226266
:id id
227267
:path (org-roam-node-file node)
228268
:level (or (org-roam-node-level node) 0)
229269
:title title
230270
:aliases (org-roam-node-aliases node)
231271
:tags (org-roam-node-tags node)
272+
:links (seq-uniq links)
232273
:properties (org-roam-node-properties node)
233274
:meta meta))))
234275

276+
(defun vulpea-db--parse-link-pair (link)
277+
"Parse LINK pair."
278+
(let ((type (car link))
279+
(value (cadr link)))
280+
(pcase type
281+
(`"http" (cons type (concat type ":" value)))
282+
(`"https" (cons type (concat type ":" value)))
283+
(_ (cons type value)))))
284+
235285

236286

237287
(defconst vulpea-db--schemata

vulpea-note.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
primary-title
4646
aliases
4747
tags
48+
links
4849
properties
4950
meta)
5051

0 commit comments

Comments
 (0)