Blogging With Hugo and Org Babel

I think I have finally found a blogging platform that makes me happy. It needs to fit my programmer's workflow – git, markup and blogging about code. Hugo with org-babel nails it.

Hugo is a really nice open-source static site generator - https://gohugo.io/. It supports a variety of markup formats including the ubiquitous markdown, but also Emacs Org Mode files. This opens the way to using org-babel for blogging with inline code snippets that can be evaluated. Hello literate blogging! And did I mention polyglot?

How Easy?

# create a new site
hugo new site donaldh.wtf

# add a theme

# create a new post
hugo new post/how-easy-is-it.org

# edit away

# try it locally
hugo serve -D
# open http://localhost:1313/

# publish
hugo && rsync -avz --delete public/ <destination>

Tour Of Inlines

Shell

echo "Hello from shell!"
Hello from shell!

Inline C

printf("Hello worldies!\n");
Hello worldies!

Perl

print "Hello World\n";
Hello World

Sqlite

select * from users;
Donald Hunter donaldh http://donaldh.wtf/

Introducing Perl 6

$*PERL

And the version is:

Perl 6 (6.c)

I cannot remember the provenance of this ob-perl6 language driver. I think I found it on github but it has since disappeared. You can get it from my dotfiles here:

https://github.com/donaldh/dotfiles/blob/master/emacs/emacs.d.symlink/local/ob-perl6.el

How do you like your fibonacci:

(1, 1, * + * ... *)[^10].join: ', '
1, 1, 2, 3, 5, 8, 13, 21, 34, 55

Graphs With Dot

test-dot.png

Bugs

Hugo uses https://github.com/chaseadamsio/goorgeous for parsing Org-mode files and it turns out there are a few bugs. They look relatively simple to fix so I'll delve into that soon.

Update: Of course, now that the bugs are resolved, the static site generator made everything below look fine.

Comment

 #+BEGIN_COMMENT
 Nobody expects any commentary.
 #+END_COMMENT

This generates spurious <p> tags inside a <pre> block, and syntax highlighting happens:

Nobody expects any commentary.

When, in fact, comments should be ignored.

Quote

 #+BEGIN_QUOTE

This also adds <p> tags, this time inside a <blockquote>, instead of <br/>

Mary had a little lamb, Its fleece was white as snow Everywhere that Mary went, The lamb was sure to go

Centered Text

 #+BEGIN_CENTER

Same thing happening here:

Hello centered world! Why such spacing though?

Verse

Mary had a little lamb, Its fleece was white as snow Everywhere that Mary went, The lamb was sure to go