Liquid Templates and Django Templates

Note to self: when I get the error:

/Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/convertible.rb:81:in `do_layout': undefined method `name' for #<Jekyll::Post:0x10f842e88> (NoMethodError)
	from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/post.rb:189:in `render'
	from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:193:in `render'
	from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:192:in `each'
	from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:192:in `render'
	from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/../lib/jekyll/site.rb:40:in `_draft_process'
	from /Users/matt/Dropbox/Blog/_plugins/drafts.rb:15:in `process'
	from /Library/Ruby/Gems/1.8/gems/jekyll-0.11.2/bin/jekyll:250
	from /usr/local/bin/jekyll:19:in `load'
	from /usr/local/bin/jekyll:19

It’s probably because I have used django template tags in the {% (end)highlight %} blocks, and omitted the {% (end)raw %} stuff.

Highlight 'highlight' blocks in Markdown/Textmate

The other day, I mentioned that I had Marked.app nicely handling my {% highlight %} blocks, and syntax highlighting them. In passing at the end, I mentioned that TextMate was still formatting them as if they were Markdown.

Now, one way around this is to indent them, but then within the code block they are indented further, and that offends my sensibilities.

Now, within TextMate, syntax highlighting is based on scopes, so to do what I want (which is the same as how HTML may have CSS or JS embedded in it), we just need a language grammar pattern that matches, and applies the relevant scope.

TextMate 2 has even nicer features, where you can set the scope (but not, as it turns out, include rules) dynamically based on a match in the pattern.

Anyway, on to the rules.

Rather than edit the Markdown rules, I wanted to just inject the language grammars in from a bundle of my own, but had no luck with this. Instead, I decided to extend the Jekyll bundle.

This is what I wanted to put in the patterns (simplified a little):

1 {
2   begin = ' "%\}\n';
3   end = ' "%\}\n';
4   name = 'source.$1.embedded.html.markdown';
5   patterns = ( { include = 'source.$1'; } );
6 }

However, as I mentioned above, the expression on line 5 does not actually include source.js patterns in this case.

Instead, I needed to have a seperate pattern for each language I wanted to include patterns from. Since mostly I work in python, html and javascript, for now those ones will do.

Oh, and the last thing is that html needs to include text.html.basic.

You can see my fork at jekyll-tmbundle. The current code is:

Marked.app previews of jekyll site

Marked.app is pretty sweet. What I like most about it is that it takes about 2 minutes for my site to regenerate, so doing things like previewing a post is a bit of a pain in the arse: so I can use Marked.app to have previews every time I save.

But most of my posts are technical, and have code fragments. I’m using Liquid Templating within Jekyll (indeed, a custom highlighter that caches the files), and these were not rendered well by Marked.app. Fair enough, too, as it doesn’t know anything about them.

So, I needed a way to have the {% highlight %} tags handled by Albino, which in turn uses Pygments.

There are posts on the Marked.app site that talk about Jekyll, but they don’t actually handle the Liquid Templating syntax. For example: github-flavored-markdown.rb

But this one does:

Now all I need is for TextMate to recognise that those block delimiters mean that it is source code and to highlight it as such.

Baked Blog

So, it looks like I’ve taken the route that quite a few others are taking lately. Although not really based on the post by Brent Simmons: A plea for baked weblogs, it probably got me thinking. Marco Arment also talked about this concept in a couple of episodes of Build and Analyze, one of which I haven’t even listened to yet.

More though, it was wanting to really be in control of what goes on the site. I moved the data from Blogger to Blogsome ages ago, and then onto a self-hosted WordPress installation. I never managed to keep the installation updated, and was forced to use PHP if I wanted to change the look.

So, this re-publish, using Jekyll, was a way to simplify the design, and generally clean everything up. I managed to pull all of the posts down using the Jekyll-WordPress tool, although since I had a very old WordPress installation, I needed to tweak the script somewhat. Mainly that was to get the tags and categories. The database structure they had to associate them was royally fucked. Eventually I got there, though.

I designed the layout myself, with a real focus on simplicity. It’s probably not quite finished, but tweaking will happen. I have a few custom (based on others work) Jekyll plugins: notably I have a generators that create the yearly/monthly/daily archives, and the tag pages. I override the highlight template tag to cache the pygments output, and add a filename if it is included.

I probably would have not had the permalinks the way I do if I had started from scratch, but didn’t really want to break incoming links. I also need to find any more missing images, and incorrectly indented code blocks.

What I haven’t done yet is get my workflow complete. I would like to be able to edit a post in my iPad (when it arrives), or from any DropBox linked computer, and when I mark it as publish, it automatically moves it to the _posts/ folder in the Jekyll directory, runs jekyll, and then deploys the data to the site. This script can take care of the file naming, from the date and the title in the yaml header, or the file modification date/time if none provided in the header. It would be nice to come up with some workflow for creating new files, but I think I’d have to write my own app for that to work on iPad.

I do have a deployment script, which just uses rsync to copy changed files:

1 #! /bin/bash
2 rsync -rcvuzm --delete /path/to/site/_site/ user@host:

I think I may create a new TextMate jekyll bundle, as the one that exists (a) cannot be installed properly from GetBundles, and (b) is missing some features. Like creating a new post, publish and deploy.

Finally, I am a bit peeved at how long it takes to build the jekyll site. With around 1500 posts, it takes about 4 minutes to generate the files. This is caching the pygments files, but the markdown files need to be re-read each time, as the several pages will change if a new post is added. That is, the index, any paginated root pages, plus all archives for the current year, and any tag pages with tags the same as the new post has. Jekyll currently recreates all pages.