Update flavourpathinfo to use Blosxom::Debug.
[blosxom-plugins.git] / gavinc / flavourpathinfo
blobe800a8bfa601166329e5cb8963f2cebe49bdeddb
1 # Blosxom Plugin: flavourpathinfo
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
3 # Version: 0.002002
4 # Documentation: 'perldoc flavourpathinfo'
5 # Follows: extensionless
7 package flavourpathinfo;
9 use strict;
11 # --- Configurable variables -----
13 # None
15 # --------------------------------
17 # use Blosxom::Debug debug_level => 1;
19 sub start { 
20     my $path_info = $blosxom::path_info;
22     # Remove any trailing /
23     $path_info =~ s! /$ !!x;
25     my $path_file = $blosxom::path_info;
26     $path_file =~ s/\.\w+$/.$blosxom::file_extension/;
27     return 1 if -e "$blosxom::datadir/$path_info" || -f "$blosxom::datadir/$path_file";
29     # debug(1, "original path_info: $path_info");
31     # Check file/flavour variant
32     if ($path_info =~ m! ^ (.*) / ([^/]+) $ !x) {
33         my $flavour = $2;
34         my $path_info_new = "$1.$flavour";
35         my $path_file = "$1.$blosxom::file_extension";
37         # debug(2, "path_file: $path_file, path_info_new: $path_info_new");
39         if (-f "$blosxom::datadir/$path_file") {
40             # debug(1, "\$path_info_new exists - updating \$blosxom::path_info");
41             $blosxom::path_info = $path_info_new;
42             $blosxom::flavour = $flavour;
43             $blosxom::path_info_yr = undef;
44             return 1;
45         }
46     }
48     # Check dir/flavour variant (implying index.flavour)
49     if ($path_info =~ m! ^ (?: (.*) / )? ([^/]+) $ !x) {
50         my $dir = $1 || '';
51         my $flavour = $2;
52         # debug(2, "dir: $dir, flavour: $flavour");
53   
54         # Check there isn't an entry matching this
55         if (-f "$blosxom::datadir$dir/$flavour.$blosxom::file_extension") {
56           # debug(2, "entry $blosxom::datadir/$dir/$flavour.$blosxom::file_extension found - skipping");
57           return 1;
58         }
59           
60         # Check $dir is a directory (sanity check - overly aggressive?)
61         if ($dir && ! -d "$blosxom::datadir/$dir") {
62           # debug(2, "dir '$dir' is set but not a directory");
63           return 1; 
64         }
66         # debug(1, "dir '$dir' not set or exists and directory - setting \$blosxom::path_info");
67         $blosxom::path_info = $dir;
68         $blosxom::flavour = $flavour;
69         $blosxom::path_info_yr = undef;
70         return 1;
71     }
73     return 1; 
78 __END__
80 =head1 NAME
82 flavourpathinfo - allows flavour designation via a trailing path component
83 instead of via a file extension
85 =head1 DESCRIPTION
87 flavourpathinfo is a syntactic sugar plugin that allows flavour designation 
88 via a trailing path component instead of via a file extension e.g.
90     http://blog.example.com/category/post/html
91     http://blog.example.com/category/post/atom
92     http://blog.example.com/category/post/trackback
94 instead of the more typical:
96     http://blog.example.com/category/post.html
97     http://blog.example.com/category/post.atom
98     http://blog.example.com/category/post.trackback
100 With index pages, the 'index' portion can also be omitted, if desired:
102     http://blog.example.com/category/html
103     http://blog.example.com/category/atom
105 map to:
107     http://blog.example.com/category/index.html
108     http://blog.example.com/category/index.atom
110 =head1 USAGE
112 If used with the 'extensionless' plugin, it should be loaded
113 *after* extensionless.
115 But should be loaded early as it manipulates $blosxom::path_info
116 e.g. as 02flavourpathinfo.
118 =head1 SEE ALSO
120 extensionless
122 Blosxom: http://blosxom.sourceforge.net/
124 =head1 BUGS
126 Please report bugs either directly to the author or to the blosxom 
127 development mailing list: <blosxom-devel@lists.sourceforge.net>.
129 =head1 AUTHOR
131 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
133 =head1 LICENSE
135 Copyright 2007 Gavin Carr.
137 This plugin is licensed under the same terms as blosxom itself i.e.
139 Permission is hereby granted, free of charge, to any person obtaining a
140 copy of this software and associated documentation files (the "Software"),
141 to deal in the Software without restriction, including without limitation
142 the rights to use, copy, modify, merge, publish, distribute, sublicense,
143 and/or sell copies of the Software, and to permit persons to whom the
144 Software is furnished to do so, subject to the following conditions:
146 The above copyright notice and this permission notice shall be included
147 in all copies or substantial portions of the Software.
149 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
150 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
151 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
152 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
153 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
154 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
155 OTHER DEALINGS IN THE SOFTWARE.
157 =cut
159 # vim:ft=perl