#!/usr/bin/perl
#
# /weblog from phroggy.com 5.071
#
# (C) 2004 Andy Lyttle, all rights reserved.
# This code may be distributed and modified under the terms of
# the GNU General Public License.
# http://phroggy.com/opensource/

BEGIN { push(@INC,'/Users/phroggy/Sites/phroggy.com-opensource/weblib'); }
use strict;
use warnings;
use Paths;
use Themes;
use Page;
use Navigation;

# This script must be placed at the root level of the web site.  It will pretend
# to be a directory; /weblog/ will load weblog.page; /weblog/1.html will load
# blog entry #1, etc.
#
# You must add this to .htaccess (replacing foo with the filename):
# <Files weblog>
#   SetHandler cgi-script
# </Files>

if(!exists $ENV{'PATH_INFO'} || $ENV{'PATH_INFO'} eq '') { # Add trailing slash
  print "Status: 301 Moved Permanently\n";
  print "Location: http://$ENV{'HTTP_HOST'}".GetURI('weblog');
  print '?'.$ENV{QUERY_STRING} if($ENV{QUERY_STRING});
  print "\n\n";
  exit;
}

# Figure out what blog entry the user wants
my $filename='filenotfound';
if($ENV{'PATH_INFO'} eq '/') {
  $filename='weblog';
} elsif($ENV{'PATH_INFO'}=~m!^/(\d+)\.html$!) {
  $filename="weblog-$1";
}

ChooseTheme();
load Page($filename)->Print;
exit;
