22 Jul 17:47
New plugin: head_meta-v0.1b
From: Steve Sergeant <stevesgt@...>
Subject: New plugin: head_meta-v0.1b
Newsgroups: gmane.comp.web.blosxom.user
Date: 2008-07-22 15:49:32 GMT
Subject: New plugin: head_meta-v0.1b
Newsgroups: gmane.comp.web.blosxom.user
Date: 2008-07-22 15:49:32 GMT
To use the expression, I had an itch that needed scratching. I couldn't find any existing bloxsom plugins to do what I needed, so I wrote something. If I've reinvented some wagon wheel I didn't know about, I'd appreciate a pointer to something better. My first working version of head_meta determines the meta tags for the top story on the page (using the meta plugin), and caches them so that they can be used in the head and foot templates. The goal was to be able to have unique keywords and page description meta tags in the head section of the html for each story. This is valuable for many search engine optimization strategies. This plugin seems to be working OK now on my site at: http://www.wildebeat.net/ I had to rename the meta plugin to "0meta" so that it would load before head-meta. I know there's a better way to do this, but I don't know what that is. I've pasted the code into this e-mail, below. As you'll see, it really doesn't have any documentation yet. Once I've done some more testing (and if I get any feedback), I'll create another version and make it available on my web site. -----SNIP----- # Blosxom Plugin: head_meta # Author(s): Steve Sergeant <stevesgt@...> # Version: 0.1b of 20080722 # Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/ # Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml # Copyright 2008 Steve Sergeant # Released under the same License as Blosxom package head_meta; # --- Configurable variables ----- # location of the cache file my $DataFile = $blosxom::plugin_state_dir.'/'."head_meta.dat"; # -------------------------------- my $read_story = 0; my $cachedmetadata = {}; my ($page_key, $cached_title) = ('',''); sub load_meta { my $metadata = {}; my $url; #open data file local *FH; if( -e "$DataFile") { open FH, "$DataFile" or return $metadata; } flock(FH, 2); while (<FH>) { chomp ($_); my @meta_items = split(m!\t!) ; $url = shift(@meta_items); foreach (@meta_items) { my ($name, $value) = m/^([^=]+)="([^"]*)"$/; $metadata->{$url}{$name} = $value; } } close (FH); return $metadata; } sub save_meta { my $metadata = shift; my $url = '' ; local *FH; open FH, ">$DataFile" or return 0; flock(FH, 2); foreach $url (keys(%{$metadata})) { my $name = ''; my @meta_items = ($url) ; foreach $name (keys(%{$metadata->{$url}})) { push @meta_items, ($name.'="'.$metadata->{$url}{$name}.'"'); } print FH join("\t",@meta_items)."\n"; } close FH; return 1; } sub start { my $key = '' ; if ($blosxom::path_info_yr ) { my @date_items ; foreach ($blosxom::path_info_yr, $blosxom::path_info_mo, $blosxom::path_info_da) { if ($_) {push @date_items, $_ }} $page_key = join('/',@date_items); } else { $page_key = $blosxom::path_info; } if ($ENV{"QUERY_STRING"}) { $page_key .= '?'.$ENV{"QUERY_STRING"}; } $cachedmetadata = load_meta(); $cached_title = $cachedmetadata->{$page_key}{'title'}; $$_ = undef foreach @keys; @keys = (); foreach $key (keys(%{$cachedmetadata->{$page_key}})) { ($cachedmetadata->{$page_key}{$key} ne 'title') and push(@keys,$key) and $$key = $cachedmetadata->{$page_key}{$key} ; } 1; } # end sub start sub story { my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; my $name = ''; if (!$read_story) { if (!$cached_title || $cached_title ne $$title_ref) { $cachedmetadata->{$page_key}{'title'} = $$title_ref; foreach $name ( keys %meta:: ) { $cachedmetadata->{$page_key}{$name} = ${$meta::{$name}} if (${$meta::{$name}}); } save_meta($cachedmetadata); } $read_story = 1; } 1; } # end sub story 1; =head1 NAME Blosxom Plug-in: head_meta =head1 SYNOPSIS Capture meta values from top-most story for use in the head and foot templates. =head1 VERSION HISTORY =head2 Version 0.1 Jul 22, 2008: It works, basically. =head1 LICENSE Blosxom and this Blosxom Plug-in Copyright 2003, Rael Dornfest Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =cut __END__ ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
RSS Feed