Script to convert graph for offline mobile browsing

I made a simple bash function to convert the .svg file from org-roam-graph into a format that I can use to browse my repository when offline on my phone (I have a http server running on the phone).

function orgroamgraph2htmlurls () {
    cp /tmp/$1 ~/zettelkasten/graph.svg || return 1
    sed -i 's|org-protocol://roam-file?file=%2Fhome%2Fjason%2Fgit%2Fzettelkasten%2F|http://127.0.0.1:12345/|' ~/zettelkasten/graph.svg
    sed -i 's|%2F|/|g' ~/zettelkasten/graph.svg
    sed -i 's|.org" xlink|.html" xlink|' ~/zettelkasten/graph.svg    
}

I had an idea to introduce two new config variables to build this functionality into org-roam:

  (setq org-roam-graph-url-extension "html")
  (setq org-roam-graph-url-prefix "http://127.0.0.1:12345/")

For a bit I was working on adding the code to org-roam-graph.el, but I soon realized that there would need to be significant changes not only to org-roam-graph--dot, but every function that touches the database.

Any thoughts? Should I enter this as an enhancement request in the Github issue tracker?

1 Like

Is this something you can use org-roam-server for?

I’m not sure how that would work on my phone, where I don’t have emacs running.

I guess you can try it and see how it goes. I thought org-roam-server also generates static html and javascript. Emacs-Server is required when you click on a node for opening the relevant note.

I saw org-protocol used in your script; I just assumed you had an Emacs Server running. The SVG graph would have run into the same issue, did it not?

Regardless of javascript-based org-roam-server or SVG graph, I didn’t think you needed to touch org-roam’s database-related functions?

After the modifications made by my script, the SVG file URLs point to http://127.0.0.1:12345, not the org-protocol: URLs. I don’t need emacs-server running on my phone, just a minimal http server.

If I used org-roam-server, I would have to do the same modifications to its output in order to make the output usable on my phone. I would rather use org-roam-graph anyway.

My idea was to build this functionality into org-roam so that my script is not needed.

I see. Thank you.

Personally I feel your script is a simpler and more elegant solution than having to change Org-roam functions that touch database, but this is just me saying it.

I guess you can try GH issue and ask the opinion of the project.

Okay, thanks for your input. I guess it depends on the design. My first hunch was to change each of these functions, but there may be a better way. Surely my fragile bash script is not a good long-term solution. I will create a GH issue.

I submitted a PR Add options for browsing a published repo via the graphviz output by jasondunsmore · Pull Request #1545 · org-roam/org-roam · GitHub

1 Like