diff options
author | Kirill Rogovoy <[email protected]> | 2021-07-17 08:15:42 +0300 |
---|---|---|
committer | Kirill Rogovoy <[email protected]> | 2021-07-17 08:15:42 +0300 |
commit | b1882a37430e54fc29d3171b9ba561415fd95682 (patch) | |
tree | ada7055ec3aef97ad443fa33d7c38a759c332110 /org-roam-ui.el | |
parent | 837d2a358c69d6a728d08a82dc7c4242ef6f21af (diff) |
Add initial org-roam-ui.el and api.d.ts
Diffstat (limited to 'org-roam-ui.el')
-rw-r--r-- | org-roam-ui.el | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/org-roam-ui.el b/org-roam-ui.el new file mode 100644 index 0000000..5f6b451 --- /dev/null +++ b/org-roam-ui.el @@ -0,0 +1,38 @@ +(require 'json) +(require 'simple-httpd) + +(define-minor-mode + org-roam-ui-mode + "Start the http API for org-roam-ui." + :lighter "" + :global t + :group 'org-roam-ui + :init-value nil + (cond + (org-roam-ui-mode + (setq-local httpd-port 35901) + (httpd-start)) + (t + (httpd-stop)))) + +(defservlet* graph application/json () + (let* ( + (nodes-db-rows (org-roam-db-query `[:select [*] :from nodes])) + (links-db-rows (org-roam-db-query `[:select [*] :from links :where (= type "id")])) + (response (json-encode (list + (cons 'nodes (mapcar 'nodes-row-to-cons nodes-db-rows)) + (cons 'links (mapcar 'links-row-to-cons links-db-rows)))))) + (insert response))) + +(defun nodes-row-to-cons (row) + (list + (cons 'id (elt row 0)) + (cons 'file (elt row 1)) + (cons 'title (elt row 8)))) + +(defun links-row-to-cons (row) + (list + (cons 'source (elt row 1)) + (cons 'dest (elt row 2)))) + +(provide 'org-roam-ui) |