From e76b691e78e273226cba9284cb8cd22a423319ed Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 2 Aug 2013 17:23:25 -0500 Subject: bucky2 --- bucky2/bin/build-splashes | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 bucky2/bin/build-splashes (limited to 'bucky2/bin/build-splashes') diff --git a/bucky2/bin/build-splashes b/bucky2/bin/build-splashes new file mode 100755 index 0000000..d5fd5c1 --- /dev/null +++ b/bucky2/bin/build-splashes @@ -0,0 +1,112 @@ +#!/usr/bin/perl + +my $TEMPLATE_DIR = "../template"; +my $BASE_DIR = "/var/www/vhosts/carbonpictures.com/httpdocs/splash"; +my $OUT_FILE = "/var/www/vhosts/carbonpictures.com/httpdocs/splash/index.html"; +my @ab = qw[b c d f g h j k l m n p q r s t v w x y z]; +unshift @ab, undef; + +# disabled for now +# build_site(read_splashes()); + +sub build_site + { + my ($years) = @_; + carp("Building site!"); + my $t_page = slurp_template("splash_list_page"); + my $t_year = slurp_template("splash_year"); + my $t_month = slurp_template("splash_month"); + my $t_day = slurp_template("splash_day"); + my $yeas = ""; + foreach my $year (sort keys %$years) + { + carp($year); + my $mons = ""; + foreach my $month (sort keys %{ $years->{$year} }) + { + my $days = ""; + foreach my $day (sort {$a cmp $b} keys %{ $years->{$year}->{$month} }) + { + my $d = $years->{$year}->{$month}->{$day}; + $days .= templatize($t_day, $d); + } + $mons .= templatize($t_month, { month => $month, days => $days }); + } + $yeas .= templatize($t_year, { year => "20".$year, months => $mons }); + } + my $page = templatize($t_page, { years => $yeas } ); + vomit($OUT_FILE, $page); + } +sub templatize + { + my ($t, $o) = @_; + while ($t =~ /\%\%([^\%]+)\%\%/) + { + my $val = $o->{lc $1}; + $t =~ s/\%\%$1\%\%/$val/g; + } + return $t; + } +sub read_splashes + { + my $years = {}; + foreach my $y (grep /^\d/, slurp_dir($BASE_DIR)) + { + my $months = {}; + $years->{$y} = $months; + foreach my $m (grep /^\d/, slurp_dir("$BASE_DIR/$y")) + { + my $days = {}; + $months->{$m} = $days; + foreach my $d (grep /^\d/, slurp_dir("$BASE_DIR/$y/$m")) + { + my $abi = 0; + foreach my $f (sort grep /html$/, slurp_dir("$BASE_DIR/$y/$m/$d")) + { + my $is_index = $f eq "index.html"; + if ($is_index) + { $k = $d; } + else + { $k = "$d".$ab[$abi++]; } + my $d = + { + key => $k, + url => "/splash/$y/$m/$d/" . ($is_index ? undef : $f), + }; + $days->{$k} = $d; + } + } + } + } + return $years; + } + +sub slurp_dir + { + my ($d) = @_; + my @files; + opendir D, $d; + while (my $f = readdir(D)) + { push(@files,$f) if $f !~ /^\./; } + closedir D; + return @files; + } +sub slurp_template + { return slurp(join "/", $TEMPLATE_DIR, @_); } +sub slurp + { + my ($f) = @_; + open F, $f; my @lines = ; close F; + return join "", @lines; + } +sub vomit + { + my ($f, $t) = @_; + carp("Writing $f"); + open F, ">", $f || die "couldn't open $f : $!"; print F $t; close F; + } +sub carp + { + my ($m) = @_; + print STDERR $m . "\n"; + } -- cgit v1.2.3-70-g09d2