#################################################
# create_site.pl
# by Daniel Wedul (daniel@wedul.com)
# Created on: January 25, 2006
# Last Modified: January 25, 2006
#*********************
# This program requires the following perl programs to be in the same directory
#   create_diary_content.pl
#	used to create the main diary page
#   create_page.pl
#	used to create each individual page.
#*********************
#  This program will find content files in folders and create webpages out of them.
#  The idea is that I only need to call this program in order to compile my entire website
#*********************
#  Usage: create_site.pl <template_path_and_file>
#    <template_path_and_file> is the path to the template file used in all the pages
#				all directories in the same folder as the template file
#				will be searched for a "content.txt"
#				If there is one, it is used to create a webpage
##################################################
use strict;
#<put the use lines here>

#################################################
############ Command Line Arguments #############
#################################################

if ($#ARGV != 0) { die "ERROR: Argument Count Mismatch.\nUsage: create_site.pl <template_file>\n"; }

my @parts = split(/[\\\/]/, $ARGV[0]);
my $Template = pop (@parts);
my $Path = join("\\", @parts);

#################################################
##################### Setup #####################
#################################################

#make sure the template exists
if (!(-e $Path."\\".$Template)) { die "ERROR: $Path.$Template does not exist.\n"; }

#get a list of all folders in the same folder as the template
opendir (INDIR, $Path);
my @files = readdir(INDIR);
closedir (INDIR);
my @dirs = ();
foreach my $entry (@files) { if (-d $Path."\\".$entry) { push (@dirs, $entry); } }

my $contentfile = "content.txt";

#################################################
#################  main program  ################
#################################################

#create the diary content
print "create_diary_content.pl wedul\\diary diary_page_template.txt dwdp\n";
`create_diary_content.pl wedul\\diary diary_page_template.txt dwdp`;

#go through each directory
foreach my $dir (@dirs) {
	#if there's a content file, create a page from it.
	if (-e $Path."\\".$dir."\\".$contentfile) {
		print "create_page.pl $Path\\$Template $dir\\$contentfile\n";
		`create_page.pl $Path\\$Template $dir\\$contentfile`;
	}
}

########################################################################
#
#  <name of sub> - <description of subroutine>
#	USAGE: <how to call this subroutine correctly>
########################################################################