Homepage Summaries in Blosxonomy

Posted Nov 15, 2005 11:09:22 PM

Whipped out a quick plugin tonight along the lines of optimizing my fold at timfanelli.com. It trims my entries down to 20 words summaries when you're viewing my home page. When you visit my homepage then, you only see the first 2 lines of text for recent entries, and you can follow the title link to view the full story.

When you browse by tags, the ReadMore plugin takes effect showing you potentially more content than you'd see on my home page, but still not the entire story (unless, of course, I neglected to add a <!-- BREAK --> to my post.). The home page summary plugin strips any markup from the summary to prevent bastardizing otherwise valid markup, and also to prevent my other plugins (such as ReadMore) from taking effect.

Home page summaries will be released when I post Blosxonomy 0.6 - but if you're curious to see how it works, here's the method I use to generate an entry's summary:

def generateSummary( body )
	# Remove markup from the body
	body = body.gsub( /<[^>]+>/, '' )

	# Split the body into words (consecutive blocks of non-whitespace)
	words = body.scan( /[^\s]+/ )

	# Take the first 20 words
	words = words.slice( 0, [20, words.length].min )
	
	# Join them back together in a paragraph.
	return "<p>%s...</p>" % words.join( " " )
end

I use this same method now to generate <atom:description> content in my Atom 1.0 renderer plugin.

Popular Tags

Recent Stories

${recent.title}

About

My name is Tim Fanelli, I am a software engineer in Northern NY. I spend most of my time working, and when I can, I try to post interesting things here.

Cigar Dossiers