eBook of Dreams

dreams code emacs .....

Later: Programming Languages and Art Media
Earlier: Making A Tiny E-Paper Status Display for the Raspberry Pi Zero

Since at least the 1980s I've kept a (very intermittent) dream journal in various forms, including

Lately I thought it might be interesting to review these and possibly use them as ideas for artworks, and I've found last format to be most amenable to later review (e.g., by exporting to a Web page or a nicely-formatted PDF).

As an avid e-book reader, I wondered yesterday, How hard might it be to turn such a dream journal into an e-book, for reading on one of my e-paper devices? (I bounce back and forth between a Kindle and a Kobo reader).

It turns out this is very easy and maps quite naturally into my existing "book workflow," which is, very briefly:

Now, my dream journal is in this format:

#+TITLE: Dreams
#+DATE: <2017-08-29 Tue>
#+OPTIONS: toc:nil num:nil

* <2017-08-29 Tue>

It was after hours in the lower, windowless floors of some science
building [....]

I wanted to:

  1. Strip off the front matter;
  2. Convert the dates to chapter headers;
  3. Add a cover image, taken more or less at random from my library of roughly 10,000 artistic reference photos and images.

For the cover, it was enough to simply pick one, crop it to roughly the dimensions of my e-reader, and put it in the same directory as my dream journal file.

With these requirements in mind, to save time on the regex wrangling, I had a short conversation with ChatGPT, and an even shorter session with my code editor, resulting in this small bash script:

#!/bin/bash

# Define paths
DREAMFILE="/Users/myuser/org/dreams.org"
EPUB_OUTPUT="$HOME/Desktop/dreams.epub"
COVER_IMAGE="/Users/myuser/org/dreams-cover.png"

# Remove leading front matter and convert Markdown to temporary file
sed -E -e '1,/^$/d' -e 's/^\* <([0-9]{4}-[0-9]{2}-[0-9]{2} [A-Za-z]{3})>$/# \1/' "$DREAMFILE" > /tmp/dreams_tmp.md

# Import temporary Markdown file into Calibre
ebook-convert /tmp/dreams_tmp.md "$EPUB_OUTPUT" --output-profile=tablet --cover="$COVER_IMAGE"

# Clean up temporary file
rm /tmp/dreams_tmp.md

I'm very happy with the results. All that remains is to consolidate some of the older dreams into the single Org Mode file I mentioned; then I can update my eBook of Dreams periodically… and peer back into the dream world at will.

Later: Programming Languages and Art Media
Earlier: Making A Tiny E-Paper Status Display for the Raspberry Pi Zero