Publishing from Day One to Pelican with Hazel and Dropbox

Posted on 2016-08-19

I'll be soon embarking on a long bike tour and was searching for a way to keep a journal of my trip but also post updates to a website. Day One was an obvious journaling choice, but with version 2, publishing isn't yet available. With a little poking around, it turned out to be fairly easy to export Day One entries and publish to Pelican (my static blog generator of choice).

I've not been a heavy user of Day One, and with the new version, I've stopped entirely until they provide end-to-end encryption with their proprietary sync service. Journaling my bike trip isn't anything I'm worried about being out in the open, and so I'll use it to keep a log of my days on the trip. At the same time, I want to keep my friends and family up-to-date on my trip. Since I use Pelican for this site, it seemed like a reasonable choice to use it for this trip and use Github Pages as an easy, free place to host it.

The first step was getting the Pelican site set up. I used the basic quickstart and put in a custom theme that I found online. The only modifications I made was using the photos plugin to make it easier to add galleries if I want in the future. Publishing to Github Pages is trivial. You can follow the steps here.

Now the fun part. Day One lets you export a journal entry as Markdown. When exported, it's compressed into a zip file which includes a folder of photos if you've included any in the journal entry. For each post, I use the export action and then upload to a folder I've created in Dropbox. I have Hazel watching this folder which will do the following:

  1. Unarchive any file that appears
  2. Move the unarchived contents into a new folder I unoriginally name "decompressed"

unarchive

I then have a separate rule watching "decompressed" which will

  1. Move any image file type into my blog's images folder
  2. Move any text file into the content folder

move_text

Step 2 here requires a little bit of extra work. Day One has some weird formatting issues and I also need to update the image urls in the entry to match what Pelican expects. The script isn't my finest, but it takes care of everything

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python

import codecs
import re
import sys
from datetime import datetime

input_file = sys.argv[1]

f = codecs.open(input_file,
                mode='r',
                encoding='utf-8').read()

# Get rid of the tabs that DayOne inserts
f = f.replace(u'\tDate:', 'Date:')
f = f.replace(u'\tWeather:', 'Weather:')
f = f.replace(u'\tLocation:', 'Location:')


# Replace default Markdown image syntax with Pelican's syntax + photos plugin
f = f.replace('![](photos/', '![]({photo}/')


title_re = re.compile(r'\n\n#\s+(.*)\n')
title_search = title_re.search(f)
now_datestring = datetime.now().strftime('%B %d, %Y at %H:%M:%S %Z')

# We need a title: header for Pelican
if title_search:
    f = 'Title: %s\n' % title_search.group(1) + f
    f = title_re.sub('', f) + "\n"
else:
    f = 'Title: Update %s\n' % now_datestring + f

if "Date:" not in f:
    f = "Date: %s\n" % now_datestring + f

with codecs.open(input_file, mode='w', encoding='utf-8') as new_file:
    new_file.write(f)

Now the file is cleaned up and in the right place. We can now publish and push to Github.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/bash

cd ~/Dropbox/blogs/biketour/pelican_site

make publish

git add ..

git commit -am 'update blog'

/Users/rjames/dev/pelican/bin/ghp-import output

git push git@github.com:rjames86/rjames86.github.io.git gh-pages:master

That's it! You can see the posts and follow my bike tour at http://rjames86.github.io

Tags: hazel pelican automation dropbox

publishing-from-day-one-to-pelican-with-hazel-and-dropbox

© Ryan M 2024. Built using Pelican.