# lib-rf-sitebuild
# by Gav Ford
# revford@blueyonder.co.uk
# http://revford.pwp.blueyonder.co.uk
# 2008-04-17, updated 2009-02-02
# subroutines and variables for the sitebuild tools
use FindBin '$RealBin';
require "$RealBin/lib-rf-date.pl";
$htmldir = "/home/gav/web/revford-site";
#$htmldir = "/home/gav/web/blue-site";
$contdir = "/home/gav/web/revford-cont";
$postdir = "/home/gav/web/posts";
$htmlver = 4.01;
sub sortpostlist
# read, cleanup and sort the posts directory
{
opendir DIR, "$postdir" or die RED, "Directory $postdir could not be opened.\n";
@postlist = readdir DIR;
closedir DIR;
@postlist = grep {$_ ne '.' and $_ ne '..'} @postlist;
my @sortedlist = sortposts(@postlist);
}
sub pageheadfull
{
$filename = $_[0];
@head = undef;
if ($htmlver eq 5)
{
# write the stock heading, doctype etc HTML5 version
push @head, '';
push @head, "\n\n";
push @head, "\n
\n";
push @head, ' '."\n";
}
else # anything else is 4.01
{
# write the stock heading, doctype etc HTML 4.01 Version
push @head, '';
push @head, "\n\n";
push @head, "\n\n";
push @head, ' '."\n";
}
# add title
push @head, " revford\/$myname<\/title>\n\n";
# add core CSS
push @head, ' '."\n";
push @head, ' '."\n";
push @head, ' '."\n";
# add CSS based on filename
if ($filename =~ m/sims2-|sims.html/)
{push @head, ' '."\n";}
elsif ($filename =~ m/computing-/)
{push @head, ' '."\n";}
elsif ($filename =~ m/roleplay-|warhammer-|gaming-|technobabble/)
{push @head, ' '."\n";}
push @head, "\n";
# add core scripts
push @head, ' '."\n";
push @head, ' '."\n";
push @head, ' '."\n";
# add any scripts based on filename
if ($filename =~ m/roleplay-modern-game-transformers/)
{push @head, ' '."\n";}
elsif ($filename =~ m/roleplay-random-npc/)
{
push @head, ' '."\n";
push @head, ' '."\n";
}
elsif ($filename =~ m/technobabble-pulp/)
{push @head, ' '."\n";}
elsif ($filename =~ m/roleplay-random-tavern/)
{
push @head, ' '."\n";
push @head, ' '."\n";
push @head, ' '."\n";
push @head, ' '."\n";
}
elsif ($filename =~ m/roleplay-dnd-game-islanders/)
{push @head, ' '."\n";}
push @head, "\n";
# add metadata based on filename
if ($filename =~ m/roleplay-menu/)
{
push @head, ' '."\n";
push @head, ' '."\n";
}
elsif ($filename =~ m/sims2-menu/)
{
push @head, ' '."\n";
push @head, ' '."\n";
}
elsif ($filename =~ m/computing-menu/)
{
push @head, ' '."\n";
push @head, ' '."\n";
}
push @head, ' '."\n";
# add a build date
push @head, builddate() . "\n\n";
# add RSS feed
push @head, ' '."\n";
# close head and open body
push @head, ''."\n".' '."\n\n\n";
return (@head);
}
sub pagefootfull
{
@foot = undef;
push @foot, "\n\n";
push @foot, ''."\n\n";
push @foot, ''."\n";
push @foot, ''."\n";
return (@foot);
}
sub newstopicslist
# News Topics
{
# read the images directory
opendir DIR, "/home/gav/web/images";
@topiclist = readdir DIR;
closedir DIR;
# just news icons
@topiclist = grep {/news\-/} @topiclist;
# remove alternate sizes and versions
@topiclist = grep {!/\-wip/} @topiclist;
@topiclist = grep {!/\-30/} @topiclist;
@topiclist = grep {!/\-70/} @topiclist;
@topiclist = grep {!/\-big/} @topiclist;
@topiclist = sort { $a cmp $b } @topiclist;
foreach (@topiclist)
{
$_ =~ s/news\-//;
$_ =~ s/\.png//;
}
return (@topiclist);
}
sub posthtml
# read a post file and return a formatted HTML version
{
my @assembly = ();
my $value = $_[0];
my $thisverypost = "$postdir\/$_[0]";
open POSTFILE, "$thisverypost" or die "File $thisverypost could not be opened.\n";
@post = ;
close POSTFILE;
$title = shift(@post);
$date = shift(@post);
$cat = shift(@post);
chomp($title);
chomp($date);
chomp($cat);
@categories = split(/ /, $cat);
push @assembly, '';
foreach (@categories)
{
push @assembly, '';
push @assembly, ' ' . "\n";
}
($mylink, $junk) = split(/\./, $value);
push @assembly, '' . $title . ' ' . "\n";
push @assembly, '' . $date . '
' . "\n";
push @assembly, @post;
push @assembly, '' . "\n\n\n";
return (@assembly);
}
sub sortposts
# sort the lists of posts by date, using the mydate stamps in the files
{
my @postlist = ();
my @sortedlist = ();
my @postlist = @_;
foreach (@postlist)
{
open POSTFILE, "$postdir/$_" or die "Error reading $POSTDIR/$_\n";
my @thispostfilecontent = ;
$postdate = $thispostfilecontent[1];
close POSTFILE;
$moddate = moddate($postdate);
# add to our table, the date as KEY and the filename as VALUE
$posttable{ $moddate } = $_;
}
foreach $key (sort {$b <=> $a}(keys %posttable))
{
# sort those KEYs, the dates into a list we can use to access them in order.
push(@sortedlist, $key);
}
return (@sortedlist);
}
1;