Skip to content

Instantly share code, notes, and snippets.

@dmgerman
Last active June 8, 2024 20:17
Show Gist options
  • Save dmgerman/8636322cd76b68a6fe74c84b566bfc77 to your computer and use it in GitHub Desktop.
Save dmgerman/8636322cd76b68a6fe74c84b566bfc77 to your computer and use it in GitHub Desktop.
dynamic block for listing Dangling links
(defun dmg-org-roam-danling-links  (&optional limit)
  (let (
        (lim (or limit 25))
        )
    (unless (integerp lim)
      (error "limit should be nil or an integer"))
    (org-roam-db-query
     (format 
      "
with dangling as
   (select dest as dest
     from links
     where type in ('\"roam\"', '\"id\"')
    except
     select id from nodes)
select source, links.pos, links.dest, links.type, title, file 
   from  dangling
   natural join links
   join nodes on (nodes.id = links.source)
   where type in ('\"roam\"', '\"id\"')
   limit %d
" lim)
  )))

(defun org-dblock-write:dmg-org-roam-dangling-links (&optional params)

  (let
      ((n (or (plist-get params :n) 20))  ; Default to 10 if :n is not provided
       )
    (insert "| source | destination|type |\n|--\n")
    (insert
     (mapconcat (lambda (link)
                  (pcase link
                    (`(,source ,pos ,dest ,type ,title ,file )
                     (format "| [[%s::%s][%s]]| [[%s:%s][%s]] |%s |\n"
                             file pos title
                             type dest dest
                             type)
                     )))
                (dmg-org-roam-danling-links n)
                ))
    (org-table-align)
       (insert (concat "\nlast evaluated: " (current-time-string)))
       ))
                 
org-dblock-write:dmg-org-roam-dangling-links
sourcedestinationtype
2023-09-24 Sun2D4266F5-7418-4586-8092-40EC2C11F032id
2024-04-15 Monbite-size-japaneseroam
2022-08-04444FFDD8-EB0B-46B5-8A01-D67F7C63DF14id
computersemacsfuzzy

last evaluated: Sat Jun 8 13:06:18 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment