My Shorts in your face

A few days after I said I’d write it up, and a few weeks after I meant to, how I do the lists of short entries between essays:

The idea is stolen wholesale from Matt’s Asides: brief entries that are displayed as one unordered list, building up as they are posted, until either a longer entry or a new day comes along to break up the list. The minute I saw them, I knew that was what I wanted, but I wasn’t quite sure how to do it in Movable Type. Then Mark Paschal wrote up a way of doing it that scared me even more (which I can’t currently find), and I sort of gave up, and just went with the Movable Type standard answer: “I know, I’ll create another weblog,” a phrasing eerily similar to “I know, I’ll use regular expressions,” quite often with similar results. Having a separate linklog in the sidebar worked, and let me post something even when I didn’t have time to go overboard on one post, but it doesn’t feel like really linking to something, in the main flow, and I’ve never created a separate weblog without being sorry I did later. That doesn’t stop me, but it’s still true.

Then a few weeks ago, when I thought about it again, I realized I didn’t actually need to find a different way to do it: I could just steal exactly Matt’s stupid hack. Create each post as a <ul><li></li></ul>, and then remove any </ul><ul> to turn it into one list.

First, create a new category for your short posts: I didn’t want to steal “Asides” from both Matt and Richard, so I cunningly chose “Shorts” to remind me to try to keep it down.

You’ll need a slightly different layout, which you could do directly in your main index template, but it’s neater and simpler to put it in a template module, with the same name, for simplicity’s sake. Mine is just

<ul>
<li class="shorts blogbody"><MTEntryBody convert_breaks="0" safe_urls="1">
 (<MTEntryCommentCount>) <a href="<MTEntryPermalink>">#</a></li>
</ul>

though probably a separate link to #comments for the comment count, and certainly some title attributes on the links, would be better.

Then, you need a way to do things differently for that one category. I tried several approaches, all of which I’ve unfortunately forgotten, along with the problems I had with them, before settling on Brad Choate’s venerable Swiss Army knife MT-Regex plugin’s <MTIfMatches>. Immediately after the </MTDateHeader>, I have

<MTIfMatches var="EntryCategory" value="Shorts">
  <MTInclude module="Shorts">
</MTIfMatches>
<MTIfNotMatches var="EntryCategory" value="Shorts">

followed by all the usual stuff for regular posts, down to a </MTIfNotMatches> just before the ending </MTEntries>.

That’s enough to give you separate one-list-item-per-<ul>, so the only thing left is to combine them into one list, which is the reason I was already looking in MT-Regex when I needed a way to do different things with the Shorts category: just like Matt’s hack, I wrap a regex that removes the end of one list and the start of the next around the whole <MTEntries> loop, so the page gets created with multiple lists, and then collapsed. It’s ugly, but at least I’m only doing it once, before saving a static file, not frying it up each time ;)

So, the whole thing (plus the template module, and Brad’s plugin) is just:

<MTAddRegex name="shorts">s|</ul>\s*<ul>||g</MTAddRegex>
<MTRegex pattern="shorts">
<MTEntries lastn="15">
<MTDateHeader>
<!-- just the usual -->	
</MTDateHeader>
<MTIfMatches var="EntryCategory" value="Shorts">
  <MTInclude module="Shorts">
</MTIfMatches>
<MTIfNotMatches var="EntryCategory" value="Shorts">
<!-- usual entry code -->	
</MTIfNotMatches>
</MTEntries>
</MTRegex>

19 Comments

Comment by Tim Hadley #
2005-04-04 23:19:44

Thanks! And it’s simpler than I expected it to be, though it’s easy to say that since I didn’t have to work it out by myself. I thought about trying over the weekend, then decided that patience would yield much less risk of frustration.

So, thanks again. Now I have something new to implement tomorrow afternoon.

Comment by Phil Ringnalda #
2005-04-05 00:21:55