1 # Blosxom Plugin: permalink
2 # Author(s): Mark Ivey <zovirl@zovirl.com>
4 # Documentation: See the bottom of this file or type: perldoc permalink
8 # --- Configurable variables -----
9 # Pick one set of formats, or modify them to make your own
12 #$root_format = '$url/';
13 #$root_flavor_format = '$url/index.$flavour';
14 #$category_format = '$url$path/';
15 #$category_flavor_format = '$url$path/index.$flavour';
16 #$file_format = '$url/$yr/$mo_num/$da#$fn.$default_flavour';
17 #$file_flavor_format = '$url/$yr/$mo_num/$da#$fn.$flavour';
19 # Blosxom Category based
20 #$root_format = '$url/';
21 #$root_flavor_format = '$url/index.$flavour';
22 #$category_format = '$url$path/';
23 #$category_flavor_format = '$url$path/index.$flavour';
24 #$file_format = '$url$path/$fn.$default_flavour';
25 #$file_flavor_format = '$url$path/$fn.$flavour';
28 #$root_format = '$url/';
29 #$root_flavor_format = '$url/index.$flavour';
30 #$category_format = '$url/$yr/$mo_num/$da$path/';
31 #$category_flavor_format = '$url/$yr/$mo_num/$da$path/index.$flavour';
32 #$file_format = '$url/$yr/$mo_num/$da$path/$fn';
33 #$file_flavor_format = '$url/$yr/$mo_num/$da$path/$fn.$flavour';
35 # Cool URI 2 (Year-only)
36 $root_format = '$url/';
37 $root_flavor_format = '$url/index.$flavour';
38 $category_format = '$url/$yr$path/';
39 $category_flavor_format = '$url/$yr$path/index.$flavour';
40 $file_format = '$url/$yr$path/$fn';
41 $file_flavor_format = '$url/$yr$path/$fn.$flavour';
43 # --------------------------------
47 use vars qw($story $category);
49 my $debug = 0; # log debug messages or not?
51 my $interpolate = $blosxom::interpolate || sub {
55 s/(\$\w+(?:::)?\w*)/"defined $1 ? $1 : ''"/gee;
59 # see perldoc for description of get_link()
62 # temporarily override existing blosxom variables & match variables
63 local ($blosxom::fn, $blosxom::flavour, $blosxom::path);
66 $blosxom::path = shift || "/";
67 warn "permalink::get_link([$blosxom::path])\n" if $debug > 0;
69 $blosxom::path =~ s!^([^/])!/$1!; # add a leading / if needed
70 $blosxom::path =~ s!/*$!!; # remove any slashes from the end
72 # strip off filename & extension
73 my $fn = ($blosxom::path =~ s[(.*)/(.*)$][$1]) ? $2 : "";
74 my $extension = ($fn =~ s!(.*)(\..*)!$1!) ? $2 : "";
76 my $fullpath = "$blosxom::datadir$blosxom::path";
78 warn "permalink::get_link() fp[$fullpath] fn[$fn] ext[$extension]\n"
81 # We look several different places trying to find a matching file. We
82 # check from the most specific to the least specific.
85 "$fullpath/$fn$extension", # exact match
86 "$fullpath/$fn.$blosxom::file_extension", # story
87 "$fullpath/$fn" # category (with flavor)
89 push @places, "$fullpath/" if ($fn eq "index"); # category (with index)
92 while (defined ($location = shift @places))
94 next unless (-e "$location");
95 warn "permalink::get_link() found $location\n" if $debug > 0;
99 $blosxom::flavour = $extension;
100 $blosxom::flavour =~ s/^\.//; # remove leading .
105 # filename is part of the path for categories...
106 $blosxom::path .= "/$fn" if ($fn and $fn ne "index");
108 # check to see if we are working on the root or not
109 if ($location =~ m!^$blosxom::datadir/*$!)
111 $out=($extension) ? $root_flavor_format : $root_format;
115 $out=($extension) ? $category_flavor_format : $category_format;
121 $out = ($extension) ? $file_flavor_format : $file_format
126 unless (defined $location)
128 warn "permalink::get_link() can't find $fullpath/$fn$extension\n";
132 # look up the date on the file
133 my $mtime = $blosxom::files{"$location"} ||
134 $blosxom::others{"$location"} ||
135 $metadate::dirs{"$location"} ||
136 $metadate::all{"$location"} ||
137 stat("$location")->mtime;
138 local ($blosxom::dw, $blosxom::mo, $blosxom::mo_num, $blosxom::da,
139 $blosxom::ti, $blosxom::yr) = blosxom::nice_date($mtime);
141 # use interpolate() to fill in all the variables in our template
142 $out = &$interpolate($out);
144 warn "permalink::get_link() returning [$out]\n" if $debug > 0;
150 my($pkg, $currentdir, $head_ref) = @_;
153 $category = get_link("/$currentdir");
164 my ($pkg, $currentdir, $date_ref, $mtime, $dw,$mo,$mo_num,$da,$ti,$yr) = @_;
166 $category = get_link("/$currentdir");
172 my ($pkg, $path, $fn, $story_ref, $title_ref, $body_ref) = @_;
173 $story = get_link("$path/$fn");
174 $category = get_link("$path");
180 my($pkg, $currentdir, $foot_ref) = @_;
182 $category = get_link("/$currentdir");
192 Blosxom Plug-in: permalink
204 Mark Ivey <zovirl1@zovirl.com>, http://zovirl.com
208 This plugin generates permalinks to help make it easier to use a consistent
209 format throughout a site. For use in flavor files, two variables are
210 exported: $permalink::story and $permalink::category. These link to the
211 current story and category, respectively. For other plugins which may
212 wish to generate links, $permalink::get_link() is provided. Given a path
213 to a file, story, or category, it returns the correct permalink.
215 $permalink::get_link() expects the path to a file, category, or story
216 (starting from $blosxom::datadir). If there is an extension present it
221 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
223 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
227 get_link() can't be used for files outside the $blosxom::datadir directory.
228 This might be a problem if your $blosxom::datadir isn't publically available
229 (by being under the web-server's document root, by using the static_file plugin,
232 Address bug reports and comments to the Blosxom mailing list
233 [http://www.yahoogroups.com/group/blosxom].
237 permalink Blosxom Plugin Copyright 2003, Mark Ivey
239 (This plugin is release under the same license as Blosxom itself)
241 Permission is hereby granted, free of charge, to any person obtaining a copy of
242 this software and associated documentation files (the "Software"), to deal in
243 the Software without restriction, including without limitation the rights to
244 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
245 the Software, and to permit persons to whom the Software is furnished to do so,
246 subject to the following conditions:
248 The above copyright notice and this permission notice shall be included in all
249 copies or substantial portions of the Software.
251 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
252 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
253 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
254 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
255 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
256 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.