This post originated from an RSS feed registered with Java Buzz
by Joey Gibson.
Original Post: User-Agent Based Content Inclusion Plugin
Feed Title: Joey Gibson's Blog
Feed URL: http://www.jobkabob.com/index.html
Feed Description: Thoughts, musings, ramblings and rants on Java, Ruby, Python, obscure languages, politics and other exciting topics.
I've just released a new Blosxom
plugin called UAInclude
that allows you to include specific content in the <head>
section of a page, based on the User-Agent of the user's browser. This
came about because when I added Todd's nice Categories
plugin. My pages looked great with Moz or other sane browsers, but they
looked like crap with IE. The reason for the
difference is that IE and Moz render various styles differently, and
my painstaking design was suffering because of it. Todd offered a
solution, but while it made the pages look better under IE, they
didn't look as good under Moz.
Thus, I wrote this plugin. It's driven by a hash of regexes that map
to (possibly non-existent) files relative to
$blosxom::datadir. Each of these regexes are compared
against the User-Agent from the current user's browser to decide which
content to include. A variable called
$uainclude::included_content is exposed and should be
added inside the <head> section in your
head.html flavour file. This variable will contain the
text of the matching file, or will be empty if the matching file
doesn't exist. (An example of when this would be useful is for a
browser like Lynx which is a
text-only browser; it will ignore styles, so why send them?) If
nothing matches, there's a default that will be served up, to account
for all the browsers that I don't know about.
This may not be useful to anyone but me, but I wanted to make it
available. Get it here
and let me know if it's useful to you or you have suggestions for
improvements.
UAInclude could certainly be generalized to support more than just
head-related stuff, but I didn't feel like thinking about it that
much. If there are requests for that, I'll think about it some more.