# Blosxom Plugin: static_sitemap -*-cperl-*- # Author: Jason Blevins # Version: 2008-02-20 # License: MIT (see below) # Documentation: Type "perldoc static_sitemap", or scroll down. # Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net package static_sitemap; use warnings; use strict; use vars qw/ $file $frequency $priority $date $yr $mo_num $da $url $path $fn /; # ----- Optional configuration ----- # To what file should the sitemap be written? $file = "$blosxom::static_dir/sitemap.xml" unless defined $file; # How often is the site updated? May be one of the following: # always, hourly, daily, weekly, monthly, yearly, never $frequency = 'daily' unless defined $frequency; # What priority is the homepage? $priority = '0.8' unless defined $priority; # ----- End configuration ----- my $package = 'static_sitemap'; sub start { # Only run in static mode return 0 unless $blosxom::static_or_dynamic eq 'static'; # Load the default templates while () { last if /^(__END__)$/; my ($comp, $txt) = /^(\S+)(?:\s(.*))?$/ or next; $txt =~ s/\\n/\n/mg; $blosxom::template{'xml'}{$package.$comp} .= $txt . "\n"; } # Determine the site URL $url = $blosxom::url . '/'; $url =~ s!//!/!; return 1; } sub end { print "$package: Generating sitemap: $file\n"; open SITEMAP, "> $file"; print SITEMAP _interpolate('head'); while(my ($file, $mtime) = each(%blosxom::files)) { # Parse the date my @utc = gmtime($mtime); $yr = $utc[5] + 1900; $mo_num = sprintf("%02d", $utc[4] + 1); $da = sprintf("%02d", $utc[3]); $date = join('-', $yr, $mo_num, $da); # Parse the path $file =~ s/$blosxom::datadir//; if ($file =~ m!/(.*)/([^.]+)\.(.+)!) { $path = $1; $fn = $2; } print SITEMAP _interpolate('story'); } print SITEMAP _interpolate('foot'); close SITEMAP; } sub _interpolate { my ($bit) = @_; my $template = &$blosxom::template('', $package.$bit, 'xml'); $template =~ s/(\$\w+(?:::\w+)*(?:(?:->)?{(['"]?)[-\w]+\2})?)/"defined $1 ? $1 : ''"/gee; return $template; } 1; __DATA__ head head head head $url head $frequency head $priority head story story $url$path/$fn.$blosxom::default_flavour story $date story 0.5 story foot content-type application/xml; charset=UTF-8 __END__ =head1 NAME Blosxom Plug-in: static_sitemap =head1 SYNOPSIS Generates an XML sitemap file in static mode. =head1 VERSION 2008-02-20 =head1 AUTHORS Jason Blevins =head1 INSTALLATION AND CONFIGURATION Place this plugin in your plugins directory. When you generate your site in static mode, a sitemap.xml file will be generated in the your $blosxom::static_dir directory. You may specify a different file by setting the C<$file> variable at the top of the file. The head, story, and foot templates may be customized by creating files static_sitemap.head.xml, static_sitemap.story.xml, and static_sitemap.foot.xml respectively. Note that since everything runs in the end() subroutine, the usual Blosxom story variables will not be available. Variables that may appear in templates include the following: $url, $frequency, $priority, $date, $yr, $mo_num, $da, $path, and $fn. Note that the default form for permanent links is $url$path/$fn.$flavour (that is, path based permanent links). If you use something else, you should change this by writing a flavour file called static_sitemap.story.xml. =head1 SEE ALSO Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/developers/plugins.html =head1 BUGS Send bug reports and comments to Jason Blevins . =head1 VERSION HISTORY 2008-02-20: Initial revision. =head1 LICENSE Copyright (c) 2008 Jason Blevins 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.