My setup has evolved a bit since I last posted. I now have Hazel watching the folder the downloads go to. When a markdown file is added it runs a script that downloads any linked images locally (using this Python package) then converts the file to ePub using the Calibre CLI. The resulting ePub file is saved to Dropbox which I can access on my e-reader and iPad. The source .md file is then deleted, so I’m only using Obsidian for the initial download.
On the rare occasions that the image download fails, I find that a manual download using the Obsidian plugin Local Images Plus generally works. But usually the whole process after the initial use of the Obsidian Web Clipper is completely automated.
I can post the script if anyone would find it helpful - but it isn’t anything complicated.
#!/bin/bash
markdown-image-downloader '(source folder here)'
# Set the source file provided by Hazel
theFile="$1"
# Set the destination folder for EPUB files
destFolder="(destination folder here)"
# Ensure the destination folder exists
mkdir -p "$destFolder"
# Extract the filename without the path and extension
fileName=$(basename "$theFile")
fileNameWithoutExtension="${fileName%.md}"
# Sanitize the filename by removing problematic characters. May not be necessary for you, but my e-Reader can’t cope with these.
sanitizedFileName=$(echo "$fileNameWithoutExtension" | tr -d '\\/:*?"<>|')
# Define the output EPUB file path
outputFile="$destFolder/$sanitizedFileName.epub"
# Convert using Calibre's ebook-convert tool.
# --no-default-epub-cover is just my preference to not have a cover
# --markdown-extensions nl2br means it reads new lines in the markdown document as new paragraphs
# --input-encoding UTF-8 --level1-toc "//h:h1" --level2-toc "//h:h2" --level3-toc "//h:h3 creates a table of contents using the different header layers. Not essential, but I use an app that complains if there’s no TOC
"/Applications/calibre.app/Contents/MacOS/ebook-convert" "$theFile" "$outputFile" --title "$sanitizedFileName" --no-default-epub-cover --markdown-extensions nl2br --input-encoding UTF-8 --level1-toc "//h:h1" --level2-toc "//h:h2" --level3-toc "//h:h3"
# Check if the conversion was successful
if [ -e "$outputFile" ]; then
# Move the original Markdown file to the Trash
mv "$theFile" ~/.Trash/
else
echo "Conversion failed for: $fileName"
exit 1
fi