1 # Blosxom Plugin: flavourpathinfo
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
4 # Documentation: 'perldoc flavourpathinfo'
5 # Follows: extensionless
7 package flavourpathinfo;
11 # --- Configurable variables -----
15 # --------------------------------
17 my $package = 'flavourpathinfo';
19 my ($level, @msg) = @_;
21 if ($debug_level >= $level) {
22 print STDERR "$package debug $level: @msg\n";
27 my $path_info = $blosxom::path_info;
29 # Remove any trailing /
30 $path_info =~ s! /$ !!x;
32 my $path_file = $blosxom::path_info;
33 $path_file =~ s/\.\w+$/.$blosxom::file_extension/;
34 return 1 if -e "$blosxom::datadir/$path_info" || -f "$blosxom::datadir/$path_file";
36 debug(1, "original path_info: $path_info");
38 # Check file/flavour variant
39 if ($path_info =~ m! ^ (.*) / ([^/]+) $ !x) {
41 my $path_info_new = "$1.$flavour";
42 my $path_file = "$1.$blosxom::file_extension";
44 debug(2, "path_file: $path_file, path_info_new: $path_info_new");
46 if (-f "$blosxom::datadir/$path_file") {
47 debug(1, "\$path_info_new exists - updating \$blosxom::path_info");
48 $blosxom::path_info = $path_info_new;
49 $blosxom::flavour = $flavour;
50 $blosxom::path_info_yr = undef;
55 # Check dir/flavour variant (implying index.flavour)
56 if ($path_info =~ m! ^ (?: (.*) / )? ([^/]+) $ !x) {
59 debug(2, "dir: $dir, flavour: $flavour");
61 # Check there isn't an entry matching this
62 if (-f "$blosxom::datadir$dir/$flavour.$blosxom::file_extension") {
63 debug(2, "entry $blosxom::datadir/$dir/$flavour.$blosxom::file_extension found - skipping");
67 # Check $dir is a directory (sanity check - overly aggressive?)
68 if ($dir && ! -d "$blosxom::datadir/$dir") {
69 debug(2, "dir '$dir' is set but not a directory");
73 debug(1, "dir '$dir' not set or exists and directory - setting \$blosxom::path_info");
74 $blosxom::path_info = $dir;
75 $blosxom::flavour = $flavour;
76 $blosxom::path_info_yr = undef;
89 flavourpathinfo - allows flavour designation via a trailing path component
90 instead of via a file extension
94 flavourpathinfo is a syntactic sugar plugin that allows flavour designation
95 via a trailing path component instead of via a file extension e.g.
97 http://blog.example.com/category/post/html
98 http://blog.example.com/category/post/atom
99 http://blog.example.com/category/post/trackback
101 instead of the more typical:
103 http://blog.example.com/category/post.html
104 http://blog.example.com/category/post.atom
105 http://blog.example.com/category/post.trackback
107 With index pages, the 'index' portion can also be omitted, if desired:
109 http://blog.example.com/category/html
110 http://blog.example.com/category/atom
114 http://blog.example.com/category/index.html
115 http://blog.example.com/category/index.atom
119 If used with the 'extensionless' plugin, it should be loaded
120 *after* extensionless.
122 But should be loaded early as it manipulates $blosxom::path_info
123 e.g. as 02flavourpathinfo.
129 Blosxom: http://blosxom.sourceforge.net/
133 Please report bugs either directly to the author or to the blosxom
134 development mailing list: <blosxom-devel@lists.sourceforge.net>.
138 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
142 Copyright 2007 Gavin Carr.
144 This plugin is licensed under the same terms as blosxom itself i.e.
146 Permission is hereby granted, free of charge, to any person obtaining a
147 copy of this software and associated documentation files (the "Software"),
148 to deal in the Software without restriction, including without limitation
149 the rights to use, copy, modify, merge, publish, distribute, sublicense,
150 and/or sell copies of the Software, and to permit persons to whom the
151 Software is furnished to do so, subject to the following conditions:
153 The above copyright notice and this permission notice shall be included
154 in all copies or substantial portions of the Software.
156 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
158 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
159 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
160 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
161 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
162 OTHER DEALINGS IN THE SOFTWARE.