Add dir/flavour support to flavourpathinfo, implying dir/index.flavour.
authorGavin Carr <gonzai@users.sourceforge.net>
Wed, 12 Sep 2007 12:11:45 +0000 (12:11 +0000)
committerGavin Carr <gonzai@users.sourceforge.net>
Wed, 12 Sep 2007 12:11:45 +0000 (12:11 +0000)
gavinc/flavourpathinfo

index 35c6353980fe98f2ea438f8f7304635ebfbf8665..6ab1b9c660a836de4752db5b0e7bb7312a202f6b 100644 (file)
@@ -1,6 +1,6 @@
 # Blosxom Plugin: flavourpathinfo
 # Author(s): Gavin Carr <gavin@openfusion.com.au>
 # Blosxom Plugin: flavourpathinfo
 # Author(s): Gavin Carr <gavin@openfusion.com.au>
-# Version: 0.001000
+# Version: 0.002000
 # Documentation: 'perldoc flavourpathinfo'
 
 package flavourpathinfo;
 # Documentation: 'perldoc flavourpathinfo'
 
 package flavourpathinfo;
@@ -24,26 +24,54 @@ sub debug {
 
 sub start { 
     my $path_info = $blosxom::path_info;
 
 sub start { 
     my $path_info = $blosxom::path_info;
-    return 1 if -e "$blosxom::datadir/$path_info";
     debug(1, "original path_info: $path_info");
     debug(1, "original path_info: $path_info");
+    return 1 if -e "$blosxom::datadir/$path_info";
 
 
-    $path_info =~ s!/$!!;
-    if ($path_info =~ m!^(.*)/([^/]+)$!) {
+    # Remove any trailing /
+    $path_info =~ s! /$ !!x;
+
+    # Check file/flavour variant
+    if ($path_info =~ m! ^ (.*) / ([^/]+) $ !x) {
         my $flavour = $2;
         my $flavour = $2;
-        $path_info = "$1.$flavour";
+        my $path_info_new = "$1.$flavour";
         my $path_file = "$1.$blosxom::file_extension";
 
         my $path_file = "$1.$blosxom::file_extension";
 
-        debug(1, "path_file: $path_file");
-        debug(1, "munged path_info: $path_info");
+        debug(2, "path_file: $path_file, path_info_new: $path_info_new");
 
         if (-f "$blosxom::datadir/$path_file") {
 
         if (-f "$blosxom::datadir/$path_file") {
-            debug(1, "munged \$path_info exists - updating \$blosxom::path_info");
-            $blosxom::path_info = $path_info;
+            debug(1, "\$path_info_new exists - updating \$blosxom::path_info");
+            $blosxom::path_info = $path_info_new;
             $blosxom::flavour = $flavour;
             $blosxom::path_info_yr = undef;
             $blosxom::flavour = $flavour;
             $blosxom::path_info_yr = undef;
+            return 1;
         }
     }
 
         }
     }
 
+    # Check dir/flavour variant (implying index.flavour)
+    if ($path_info =~ m! ^ (?: (.*) / )? ([^/]+) $ !x) {
+        my $dir = $1 || '';
+        my $flavour = $2;
+        debug(2, "dir: $dir, flavour: $flavour");
+  
+        # Check there isn't an entry matching this
+        if (-f "$blosxom::datadir$dir/$flavour.$blosxom::file_extension") {
+          debug(2, "entry $blosxom::datadir/$dir/$flavour.$blosxom::file_extension found - skipping");
+          return 1;
+        }
+          
+        # Check $dir is a directory (sanity check - overly aggressive?)
+        if ($dir && ! -d "$blosxom::datadir/$dir") {
+          debug(2, "dir '$dir' is set but not a directory");
+          return 1; 
+        }
+
+        debug(1, "dir '$dir' not set or exists and directory - setting \$blosxom::path_info");
+        $blosxom::path_info = $dir;
+        $blosxom::flavour = $flavour;
+        $blosxom::path_info_yr = undef;
+        return 1;
+    }
+
     return 1; 
 }
 
     return 1; 
 }
 
@@ -71,6 +99,16 @@ instead of the more typical:
     http://blog.example.com/category/post.atom
     http://blog.example.com/category/post.trackback
 
     http://blog.example.com/category/post.atom
     http://blog.example.com/category/post.trackback
 
+With index pages, the 'index' portion can also be omitted, if desired:
+
+    http://blog.example.com/category/html
+    http://blog.example.com/category/atom
+
+map to:
+
+    http://blog.example.com/category/index.html
+    http://blog.example.com/category/index.atom
+
 =head1 USAGE
 
 Should be loaded early as it manipulates $blosxom::path_info
 =head1 USAGE
 
 Should be loaded early as it manipulates $blosxom::path_info