#!/usr/bin/perl

# sitebuild-update-index
# by Gav Ford
# revford@blueyonder.co.uk
# http://revford.pwp.blueyonder.co.uk
# 2008-01, updated 2009-02-02
# build the index page


use Term::ANSIColor qw(:constants);
use FindBin '$RealBin';


require "$RealBin/lib-rf-sitebuild.pl";
require "$RealBin/lib-rf-babble.pl";
require "$RealBin/lib-rf-date.pl";


$outfile      = "/home/gav/web/revford-site/index.html";
#$outfile      = "/home/gav/web/blue-site/index.html";

$indexfile    = "/home/gav/web/revford-parts/page-indexbox.cont";
$topicoutfile = "/home/gav/web/revford-parts/page-topicslist.cont";
#$topicsbox   = "true";


@pagehead   = pageheadfull();
@pagefoot   = pagefootfull();
@newslist   = newstopicslist();
@sortedlist = sortpostlist();



# build the topics box, save it to a file so it can be reused elsewhere
push @pagetopics, '<div class="newstopics">' . "\n";
foreach (@newslist)
  {
  push @pagetopics, '<a href="updates-'. $_ .'-1.html">';
  push @pagetopics, '<img src="images/news-' . $_  . '.png" alt=" "></a>' ."\n";
  }
push @pagetopics, '</div>';


open OUTFILE, "> $topicoutfile" or die RED, "File $topicoutfile could not be opened.\n";
  print OUTFILE @pagetopics;
  close OUTFILE;


# read the index content box from a file
open FILE, $indexfile or die RED, "File $indexfile could not be read.\n";
  @pageindex = <FILE>;
  close FILE;



# assemble the page
open OUTFILE, "> $outfile" or die RED, "File $outfile could not be opened.\n";

print OUTFILE @pagehead; 

print OUTFILE @pageindex; 


if ($topicsbox eq "true") {print OUTFILE @pagetopics};


print OUTFILE '<div class="tallbox">' . "\n";
print OUTFILE '<noscript><hr></noscript>' . "\n\n\n";
print OUTFILE '<p class="blognav">| <a href="updates-2.html">More</a> |</p>' . "\n";

print OUTFILE '<h1>revford blog</h1>' . "\n";
print OUTFILE '<p class="subtitle">' . babble() . '</p>' . "\n\n";

print OUTFILE '<hr>'."\n";

foreach (0..19)
  {
  my $value = $posttable{$sortedlist[$_]};

  print OUTFILE posthtml($value);
  };


print OUTFILE '<p class="blognav">| <a href="updates-2.html">More</a> |</p>' . "\n";
print OUTFILE '</div>' . "\n";

print OUTFILE @pagefoot;

close OUTFILE;

