Eyes East

feed icon Subscribe / Latest posts / Latest links / Get in touch / About

Django Recipe: A template for any blog post

February 13, 2010 at 8:08 p.m.

One more quick code recipe before I jump back into the Journalism to Django series. In my last post, I mentioned that I set up permalinked paragraphs on a couple recent entries, using a different technique on each one. You might be wondering how I did that.

This is documented, but it took me a while before I realized how simple it is. The key is Django's get_template and select_template functions, which are part of the template system. Get template takes a string and gets a template. Select template chooses the first one that matches from a list or ...

Read more...

JavaScript Recipe: Adding Paragraph-level Permalinks

February 12, 2010 at 5:24 p.m.

Paragraph-level permalinks are hot, right? Let's do this in JavaScript, just for fun.

Remember from my last post that all you need is a block of HTML and something to parse it with? This is pretty much what JavaScript was made to do.

var entry = document.getElementById('entry-text');
var paras = entry.getElementsByTagName('p')

Assuming you have a div with id="entry-text", we've just grabbed every paragraph below it and created an array called paras. Simple enough.

Now, like we did with Python and Beautiful Soup, we're just going to loop through that list of paragraph elements, add ...

Read more...

Python Recipe: Adding Paragraph-Level Permalinks

February 11, 2010 at 9:06 p.m.

I mentioned in my last post how useful Ben Welsh's code recipe's are. Count this post as my effort to encourage the practice among coding journalists.

Since launching the NewsHour's Annotated State of the Union, I've gotten a few questions about how it worked, particularly about linking comments to paragraphs. What's needed is paragraph-level permalinks. As it turns out, that's pretty easy to do.

The first thing you'll need is a block of clean HTML. Then, you'll need something that can parse and modify that HTML. Fortunately, tools abound.

Doing it server ...

Read more...