I have tried diagramming on a couple posts but never had a good workflow because I didn’t want Mermaid.js with a massive payload, but maybe D2 is a contender!?
I watched this excellent video: Beautiful diagrams in Emacs by Torstein Krause Johansen and it got me interested in reexamining an easy way to integrate diagramming that is both declarative and tangled out, my Mermaid attempt wasn’t that.
Yak shaves
I’ve started this blog post as a way to try it out directly in my workflow, so this is happening live and already has yak-shave vibes. So, let’s see how many yaks we shave:
- Oh yeah, just realized that to actually test it fully I need to update my custom build OS image to add the
d2CLI tool and getting it pushed up to my container registry and pulling it down to the laptop to test. - It was a yak-shave after all since elpa.gnu.org kept failing until I realized that it was not code but the remote machine was on VPN 😭. But now I have
d2in my build environment. - I struggled with trying to write a file and then include it and then realized that tangling it inline also includes it in the export, which is cool. But tangling my whole file isn’t doing the job, manually tangling the block does work. * many minutes later * Right, that doesn’t work because of my workflow of org > ox-hugo > md > hugo.
- Had to go through and update my Hugo templates to handle SVG images (since resize for thumbnails doesn’t make sense and hence fails).
- The org file still isn’t tangling the
d2block in the build pipeline but it does tangle out other blocks…. arrrggghhh! - Alright, it needs to tangle with the rest of the file but not rendered inline, small yak shaved with
:exports none :noeval - Woof, now I have to update the Hugo shortcode so it doesn’t try to resize a svg.
:flagsor:cmdlineisn’t supported byd2-mode’sorg-babel-execute:d2function natively, so all cli parameters (like themes) need to be passed viad2-flagsand can’t easily be customized per block.
|
|
Post completion reflection: 1 and 2 were completely unnecessary and would have been obvious if I thought through how I handle images and I wouldn’t use the auto-inlining because I add images as figures with alt-text. 7 and 8 were the only real dependencies, the rest was learning churn… a bit sad/frustrating but definitely learned stuff.
D2 Diagrams
Alright now I can finally try D2 diagramming (in my workflow). Here’s the most basic one and it’s reasonably small overhead (now that I have shaved a heard of yaks) and can be reduced further if I made another short code to add in the Hugo image boiler plate and read in org properties to reduce manual entry effort.
|
|
Styling is fairly simple but I can’t figure out to show to style all connectors but not shape borders.
|
|
Webring diagramming
So if I were to recreate the webring diagram which started this “I wonder if” thought HOURS ago, it would look like:
|
|
And when I was trying to explain a broken webring, I could get quite fancy without that much effort:
|
|
So in conclusion: D2 is great, now that the infrastructure is set up and I have a tiny bit of familiarity with it, it is fairly easy to use. I still have to tangle out a file and then include it manually but that could be templated/automated but this side quest ended up being my most of my day so I’m putting a pin in it.