Blogging Archives, page 9

Blogging about blogging, how meta.

Elastic Homepage and Hidden Comments

In the background, I’ve been making a few improvements to my blog, some of which I think are pretty cool.

The Elastic Homepage

The first was inspired by my rampant blogging over the holidays, partly trying to keep in contact with friends and the fam, but also because I was spending an inordinate amount of time trying to get from Phoenix to Austin. Plus PHX had FREE! and ubiquitous wireless, so what else was a blogger to do?

I also noticed, as expected, that the traffic to my blog dropped off precipitously during the holidays. So there I was, posting once or twice as day, and with only 5 posts showing up the homepage, I was concerned that when people took a break from celebrating with their families to check their email and my blog, half of my ordeal might have scrolled off into the archives!

It occured to me that I needed to whip up some hybrid between Movable Type’s default behavior of showing the last X days worth of posts and just about every other platform’s behavior of displaying the last N posts. I could manually expand the number of posts showing up on my homepage, but I thought it’d be a LOT cooler if the homepage automatically “stretched” so that it displayed more posts when I’m posting frequently, but never dropped below some minimum threshold when I can barely squeeze out a post a week.

So that’s what I’ve done. At minimum you’ll see the last five posts on the homepage, but if I happen upon a stroke of unexpected brilliance, you’ll see at most the last 8 days worth of posts. Which, if you check my blog once a week (the old fashioned way), means you won’t miss a thing. Ha!

Update: The Elastic Homepage Howto

Want to implement the Elastic Homepage yourself? It’s based on Justin Blanton’s Limit number of posts with WordPress, so first you’ll have to set the Show at most posts option under Options > Reading to some large number. Choose something that you wouldn’t expect to exceed in the maximum time period you specify below. Be aware that this will affect how many posts show up in your archive, category, and search result pages. The updated code below will then override this number based on variables you specify.

In your index.php template file, change the following code (as taken from the default template):

<?php if (have_posts()) : ?>
		
    <?php while (have_posts()) : the_post(); ?>

To this:

<?php if (have_posts()) : 

    // variables to configure elastic homepage
    $minimum_posts_to_display = 5;
    $maximum_days_to_display  = 8;

    // initialize counter for elastic homepage
    $elastic_homepage_counter = 0;

    // convert days to seconds (60*60*24 = 86400)
    $maximum_days_to_display *= 86400;
?>
		
    <?php while (have_posts()) : the_post(); 

        // stop printing posts when the minimum number of posts has been reached
        // and the current post is older than the number of days specified above
        $age_of_current_post = time() - get_the_time('U');
        if (($elastic_homepage_counter >= $minimum_posts_to_display) && 
            ($age_of_current_post      >  $maximum_days_to_display))
        { 
            break; 
        }
        $elastic_homepage_counter++;
    ?>

Then modify the variables $minimum_posts_to_display and $maximum_days_to_display to configure the elasticity of the homepage to your liking.

Hidden Comments

Show Comments link screenshotThe next idea came to me while I was reading a recent comment on my monthchunks plugin post, which continues to generate interest and thus occasionally new comments. The utility of scrolling down a narrow column of 40 odd comments loses its allure pretty quickly. Wouldn’t it be cool, I thought, if I could hide the old comments without making them inaccessible, in order to bring the most recent to the top, while still sorting them in chronological order.

Purple Fade Technique 1 screenshotWith a teensy bit of JavaScript and a little WordPress theme hacking, I wrapped the first bunch of comments in a div so that only the most recent 10 comments lived outside of this div. Then I set display:none on the div so it doesn’t show up, but I added a link at the top of the comments that says Show comments: 1 through X which makes the div reappear and hides the link. Ah, so satisifying.

Purple Fade Technique 2 screenshotI came back a day or two later and realized that clicking the link to show the hidden comments happens so fast that it’s hard to tell what exactly changed. What a perfect opportunity to try the Yellow Fade Technique, popularized by the folks at 37Signals. [Unfortunately the images on the YFT post are currently broken, so it doesn’t do you much good.] However, the gist is that if you change something subtly on a webpage, you should provide the user with some kind of visual cue that something happened, like fading the updated info from yellow to white.

Purple Fade Technique 3 screenshotPerfect! All I needed was a library that would fade from any color to any background color. Thank you Adam Michela for doing the heavy lifting so I didn’t have to. His Fade Anything Technique does exactly that. I grabbed the code, plugged in my purplish highlight color and my beige background color, so now when you click the link to show the hidden comments, they gradually fade from purple to beige. SO COOL!

Check out Television Abstinence (currently has 12 comments, so 2 are hidden) to see this in action.

MT doesn’t understand paragraphs

Let’s say I create the following entry in Movable Type 3.2. Five paragraphs with the middle three enclosed in a blockquote. Fairly standard blog post skeleton.

paragraph 1

<blockquote>
paragraph 2

paragraph 3

paragraph 4
</blockquote>

paragraph 5

What HTML do I want MT to produce as a result?

<p>paragraph 1</p>

<blockquote>
<p>paragraph 2</p>

<p>paragraph 3</p>

<p>paragraph 4</p>
</blockquote>

<p>paragraph 5</p>

What HTML does MT actually produce? Invalidly nested HTML. Fun.

<p>paragraph 1</p>

<blockquote>
paragraph 2

<p>paragraph 3</p>

<p>paragraph 4<br />
</blockquote></p>

<p>paragraph 5</p>

What a bummer. I would consider this a fairly critical bug. Oh, and WordPress gets this right. Workaround: manually mark up the paragraphs inside the blockquote. One more thing I wish I didn’t have to remember.

This post first appeared on From the Belly of the Beasts, a weblog from some of the people who build O’Reilly websites.

Seed on MT

An interesting bit about how Seed magazine’s site was implemented in MT:

So, we pitched it. And, to our mild amazement, we won the gig. We were likely the underdogs, but I think our strong confidence in MT and our success with Sciencegate helped us out. Plus — we were passionate about the project. Seed is a new breed of science magazine, with truly lofty ideals, and we wanted to be part of that.

This post first appeared on From the Belly of the Beasts, a weblog from some of the people who build O’Reilly websites.

Why don’t your feeds display in my browser?

From the mailbags this morning, I got the following bug report:

You have two broken links to subscribe to RSS feeds. In both cases, my browser tries to open/save to my desktop rather than open the rss feed in a browser window.

My response, though nothing new, I thought some might find interesting, at least for future reference.

rfc3023.jpg

“We return our feeds with the correct MIME type for the syndication format. In the case of RSS 2.0 that would be application/rss+xml, per RFC 3023.

“This is important because it means your browser should able to use this information to determine the file format and launch the appropriate helper program or plugin (e.g. a newsreader) to read the file. We realize in practice this may not be the case. Internet Explorer has not been revised in over 4 years and Firefox requires some additional configuration in order to display application/rss+xml files in the browser (but the latter can be done).

Some people advocate sending RSS feeds out with a more generic text/xml MIME type, which most browsers natively know how to parse and display. However, doing so would make it impossible for browsers (and more importantly, newsreaders) to know what sort of XML file you’re downloading and what helper application to load.”

This post first appeared on From the Belly of the Beasts, a weblog from some of the people who build O’Reilly websites.

One enclosure per item

Though it’s not explicitly specified in the spec (as not much really is) I thought I’d mention here for future reference that RSS 2.0 really only expects there to be one enclosure per item.

This question comes up from time to time, and I’ve resisted answering it directly, thinking that anyone who really read the spec would come to the conclusion that RSS allows zero or one enclosures per item, and no more. The same is true for all other sub-elements of item, except category, where multiple elements are explicitly allowed. The spec refers to “the enclosure” in the singular. Regardless, some people persist in thinking that you may have more than one enclosure per item. Dave Winer

This post first appeared on From the Belly of the Beasts, a weblog from some of the people who build O’Reilly websites.