tagging: Allow using titles in for related stories.
[matthijs/upstream/blosxom-plugins.git] / gavinc / flavourpathinfo
1 # Blosxom Plugin: flavourpathinfo
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
3 # Version: 0.002002
4 # Documentation: 'perldoc flavourpathinfo'
5 # Follows: extensionless
6
7 package flavourpathinfo;
8
9 use strict;
10
11 # --- Configurable variables -----
12
13 # None
14
15 # --------------------------------
16
17 # use Blosxom::Debug debug_level => 1;
18
19 sub start { 
20     my $path_info = $blosxom::path_info;
21
22     # Remove any trailing /
23     $path_info =~ s! /$ !!x;
24
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";
28
29     # debug(1, "original path_info: $path_info");
30
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";
36
37         # debug(2, "path_file: $path_file, path_info_new: $path_info_new");
38
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     }
47
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         }
65
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     }
72
73     return 1; 
74 }
75
76 1;
77
78 __END__
79
80 =head1 NAME
81
82 flavourpathinfo - allows flavour designation via a trailing path component
83 instead of via a file extension
84
85 =head1 DESCRIPTION
86
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.
89
90     http://blog.example.com/category/post/html
91     http://blog.example.com/category/post/atom
92     http://blog.example.com/category/post/trackback
93
94 instead of the more typical:
95
96     http://blog.example.com/category/post.html
97     http://blog.example.com/category/post.atom
98     http://blog.example.com/category/post.trackback
99
100 With index pages, the 'index' portion can also be omitted, if desired:
101
102     http://blog.example.com/category/html
103     http://blog.example.com/category/atom
104
105 map to:
106
107     http://blog.example.com/category/index.html
108     http://blog.example.com/category/index.atom
109
110 =head1 USAGE
111
112 If used with the 'extensionless' plugin, it should be loaded
113 *after* extensionless.
114
115 But should be loaded early as it manipulates $blosxom::path_info
116 e.g. as 02flavourpathinfo.
117
118 =head1 SEE ALSO
119
120 extensionless
121
122 Blosxom: http://blosxom.sourceforge.net/
123
124 =head1 BUGS
125
126 Please report bugs either directly to the author or to the blosxom 
127 development mailing list: <blosxom-devel@lists.sourceforge.net>.
128
129 =head1 AUTHOR
130
131 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
132
133 =head1 LICENSE
134
135 Copyright 2007 Gavin Carr.
136
137 This plugin is licensed under the same terms as blosxom itself i.e.
138
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:
145
146 The above copyright notice and this permission notice shall be included
147 in all copies or substantial portions of the Software.
148
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.
156
157 =cut
158
159 # vim:ft=perl
160