intertwingly

It’s just data

Blosxom excerpts


Dave Walker: The discussion here got me thinking as to how to include both full feeds and meaningful summaries in my syndicated feeds.

My weblog software's design is based on blosxom's, with entries stored in the familiar title followed by body format.  On my longer entries, such as this one, the first element in the body is a div tag with a class of excerpt, something that I parse out with a set of regular expressions.  This same approach can be implemented in blosxom as a plugin:

package excerpt;

use strict;
use warnings;

our $data;

sub start {
  1;
}

sub story {
  my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
  ($data,$$body_ref) = ($$body_ref =~ /(?:<div class="excerpt">(.*?)<\/div>)?\s*(.*)/s);
  return 1;
}

1;

For entries without an excerpt, the body is left untouched, and $excerpt::data will be a string of length zero.  For entries with an excerpt, the excerpt is stripped from the body and placed into $excerpt::data.