Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide better way to shorten long urls #2427

Open
1 task
bigos opened this issue Apr 13, 2024 · 2 comments
Open
1 task

Provide better way to shorten long urls #2427

bigos opened this issue Apr 13, 2024 · 2 comments

Comments

@bigos
Copy link

bigos commented Apr 13, 2024

Brief Abstract

When I generate a graph the long URLs ruin the graph

Long Description

There may be a configuration that I could add to my init.el instead of patching the function. If it exists please provide the example.

Proposed Implementation (if any)

find (defun org-roam-graph--format-node (node type)

node-properties (append `(("label" . ,(concat type ":" node)))

and note the commented out node replaced with (substring node (- (length node) 10))

      (setq node-id node
            node-properties (append `(("label" . ,(concat type ":" ;node
                                                          (substring node (- (length node) 10))
                                                          )))
                                    (when (member type (list "http" "https"))
                                      `(("URL" . ,(xml-escape-string (concat type ":" node)))))))

Please check the following:

  • No similar feature requests
@bigos
Copy link
Author

bigos commented May 8, 2024

truncate-string-to-width may be better, but does anybody know how to write a function advise https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html so I can do it in my own init file?

(defun org-roam-graph--format-node (node type)
  "Return a graphviz NODE with TYPE.
Handles both Org-roam nodes, and string nodes (e.g. urls)."
  (let (node-id node-properties)
    (if (org-roam-node-p node)
        (let* ((title (org-roam-quote-string (org-roam-node-title node)))
               (shortened-title
                (org-roam-quote-string
                 (pcase org-roam-graph-shorten-titles
                   (`truncate (truncate-string-to-width title org-roam-graph-max-title-length nil nil "..."))
                   (`wrap (org-roam-word-wrap org-roam-graph-max-title-length title))
                   (_ title)))))
          (setq node-id (org-roam-node-id node)
                node-properties `(("label"   . ,shortened-title)
                                  ("URL"     . ,(funcall org-roam-graph-link-builder node))
                                  ("tooltip" . ,(xml-escape-string title)))))
      (setq node-id node
            node-properties (append `(("label" . ,(concat type ":" ;node
                                                          (truncate-string-to-width node 15)
                                                          )))
                                    (when (member type (list "http" "https"))
                                      `(("URL" . ,(xml-escape-string (concat type ":" node))))))))
    (format "\"%s\" [%s];\n"
            node-id
            (mapconcat (lambda (n)
                         (org-roam-graph--dot-option n nil "\""))
                       (append (cdr (assoc type org-roam-graph-node-extra-config))
                               node-properties) ","))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant