Ditched Blogofile for Hugo

November 6, 2016

Apparently I only update this blog when I transition from technology to technology. It’s been a good six years. I hadn’t kept up on the blogofile updates, and so I decided to go wholesale into hugo. I’ve tried to keep the URLs about as close as I could get.

The site is now also hosted by S3, so it should be pretty stable.

For reference, here’s a quick and dirty script I wrote to convert from Blogofile 0.6 to Hugo. It’s buggy and will probably delete your hard drive, but I’ll put it out here for future Googling anyway.

I wonder if anyone has a RSS feed poking at this anymore? Leave a comment and say hi!

import datetime
import dateutil.parser
import glob
import html2text
import re
import sys

for file_name in glob.glob('before/*'):
    print 'Processing: %s' % file_name
    html_file = open(file_name, 'r')
    lines = html_file.readlines()

    categories = lines[1].strip()
    categories = '[ ' + ', '.join(['"%s"' % i for i in categories.split(': ')[1].split(', ')]) + ' ]'
    print categories

    date = lines[2].strip().split(': ')[1]
    date = dateutil.parser.parse(date).strftime('%Y-%m-%dT%H:%M:%S-07:00')

    guid = lines[3].strip()
    permalink = lines[4].strip()

    tags = lines[5].strip()
    tags = '[ ' + ', '.join(['"%s"' % i for i in tags.split(': ')[1].split(', ')]) + ' ]'

    title = lines[6].strip().split(': ')[1]

    body = lines[8:]
    body = ''.join(body)
    body = ''.join([i if ord(i) < 128 else ' ' for i in body])
    out_file_name = file_name.split('. ')[1].split('.')[0]
    out_file = open('content/%s.md' % out_file_name, 'w+')

    print >> out_file, '+++'
    print >> out_file, 'title = "%s"' % title
    print >> out_file, 'date = %s' % date

    print >> out_file, 'draft = false'

    print >> out_file, 'categories = %s' % categories
    print >> out_file, '+++'
    print >> out_file, ''
    try:
        print >> out_file, html2text.html2text(body)
    except Exception as e:
        print 'exception: %s on %s' % (e, body)
        sys.exit(1)

    html_file.close()
    out_file.close()
comments powered by Disqus