summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api.d.ts15
-rw-r--r--org-roam-ui.el38
2 files changed, 53 insertions, 0 deletions
diff --git a/api.d.ts b/api.d.ts
new file mode 100644
index 0000000..3bbea6d
--- /dev/null
+++ b/api.d.ts
@@ -0,0 +1,15 @@
+export type OrgRoamGraphReponse = {
+ nodes: OrgRoamNode[]
+ links: OrgRoamLink[]
+}
+
+export type OrgRoamNode = {
+ id: string
+ file: string
+ title: string
+}
+
+export type OrgRoamLink = {
+ source: string
+ dest: string
+}
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)