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

De nada. I’m pretty sure it’ll work out in the same freeing way for you it has for me. Just have to be careful not to go overboard on shorts: I keep winding up with more sidebar than posts, and then the sidebar wraps around below the main content, and I have to come up with something to write a longer post about whether I want to or not.

 
 
Comment by Phil Ringnalda #
2005-04-05 00:27:06

but I can’t remember the second one. Or was it the first?

That’s what I get for writing a post over the course of three hours, with dinner and feed reading and email mixed in, and then not reading through it before posting it: I honestly didn’t realize that I approvingly quoted ”now you have two problems” and then in the next paragraph said ”then I knew, I’d use regular expressions!”

Now I’m just waiting for the first bug report that’s going to be the result of someone putting something other than just whitespace between </ul> and <ul>, so the regex breaks.

 
Comment by Matt #
2005-04-05 06:18:42

+1, if just for the title. :)

 
Comment by Mark Paschal #
2005-04-05 11:10:07

Oh, this scary code? :)

Comment by Phil Ringnalda #
2005-04-05 20:08:44

The very one. Not quite as scary as I remembered it, I must have been having a stupid day. But there’s still parts of it I don’t quite grasp, and whatever I don’t understand, I break. Phil’s Corollary.

Comment by Mark Paschal #
2005-04-07 16:58:07

It was pretty scary when I looked it up: the plugin I wrote to auto-format <code/> blocks was broken and it was all squished into one line.

The hard part is to wrap adjacent quick link <li/>s into one <ul/>. That is, what you did with MT-Regex, only adding <ul> and </ul> in the right places instead of removing them from the wrong ones. :)

 
 
 
Comment by Quadsk8 #
2005-04-05 13:48:44

Can you style your feed the same?

Comment by Phil Ringnalda #
2005-04-05 14:29:42

Don’t think so: you would have to maintain state for every subscriber, so that you could put any new shorts since their last fetch into a new list. Otherwise, lots of readers will never see them, and others will be forced to remember what they have and haven’t seen.

 
 
Comment by Tim Hadley #
2005-04-05 20:59:40

Hm. I got an error (which silly me didn’t write down before backing out the code in my main index template) saying that the MTIfMatches tag was unrecognized. I’d installed MT-Regex. But I’m too tired right now to go back and try to figure it out. Maybe I’ll try again tomorrow.

I use dynamic page generation. I don’t know if that makes a difference.

Comment by Phil Ringnalda #
2005-04-05 21:53:58

Oof. That would do it: MT-Regex is Perl-only (as far as I know, I haven’t been paying enough attention since last summer), so you need a PHP way of saying ”am I in this category or not?” and also of slicing out the extra </ul><ul>s. Not especially difficult, but I’m not even sure I’ve got a dynamic test blog laying around anymore: I played with in in the 3.0x beta days, but it just seemed like a worst-of-both-worlds thing (and, mostly, like I would have to port a bunch of plugins that I was too lazy to port).

So, bottom line, I’ll do it, but you’ll have to nag me. I’ve gotten terrible about doing whatever’s been mentioned most recently, not whatever most needs doing or is most overdue, so you have to stay on the top of my stack.

Comment by Tim Hadley #
2005-04-06 11:26:39

Don’t worry about it! I’m sure you have more important things to do.

I may switch back to static pages, but since I don’t have much traffic and I don’t pay for a lot of space, I put disk space at a higher premium than the processing time it would take to dynamically generate the pages.

 
 
 
2005-04-05 21:24:34

This, I may have to steal. Er, borrow. Thanks, Phil, as always!

Comment by Phil Ringnalda #
2005-04-05 21:57:43

Oh, do do do! Your Coasters (which I somehow had been forgetting to subscribe to) don’t give you quite enough room to talk around a link, and we need some way to get a little of you between times when the need to rant bursts out.

 
 
Comment by Phil Ringnalda #
2005-04-06 23:18:04

Hand trackback, since my anti-spam and Roger’s RDF disagree (and I’m starting to think I’m wrong, damn it):

Shorts as a JournURL template. I feel bad that the sort of thing JournURL is, a hosted, community-oriented site, doesn’t do much for me, because every time I see inside it, it clearly kicks a whole lot of ass.

 
Comment by Jesse Ruderman #
2005-05-19 14:38:05

Your ”similar results” link gives me a 404 error.

Comment by Phil Ringnalda #
2005-05-19 15:25:39

Some people, when confronted with a problem, think ’I know, I’ll link to Google.’ Now they have two problems.

— Phil Ringnalda, in his comments.

Dunno whether Google purged every trace of jwz’s most famous quip, or they’re just having troubles of some sort, but I can’t find anything other than thousands of people misquoting it right now.

 
 
2005-11-21 19:50:01

[…] Having previously ganked Matt’s Asides for MT, I’ve now just dropped in the original, but I haven’t figured out how to have the front page show ten posts or sections of Shorts, rather than just ten Shorts when I drop in a bunch, or how to manage them in the feed (maybe by excluding them until midnight, and then dropping them in as a single post?) so, sing heigh ho, the unordered list: […]

 
Comment by Sits #
2006-05-22 08:49:07

Re: jwz quote:

Yes it disappeared a few years ago. The question is whether it was inspired by a stern quote?

”When faced with a problem, some people say ’Let’s use AWK.’ Now they have two problems.”

as seen in http://groups.google.com/group/alt.quotations/browse_thread/thread/a008433940861d4e/dcee3d3682dd0470

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <del datetime="" cite=""> <dd> <dl> <dt> <em> <i> <ins datetime="" cite=""> <kbd> <li> <ol> <p> <pre> <q cite=""> <samp> <strong> <sub> <sup> <ul> in your comment.