#!/usr/bin/env perl use strict; use warnings; use utf8; use Template; use YAML; # Static variables my $static = YAML::LoadFile "variables.yml"; my @files = ; # Directory listings my $list; sub list { my ($a, $b) = @_; my $tmp = "\n"; $list->{$a}->{$b} = $tmp; } # Directory listings list "doc", "user"; list "doc", "development"; for my $file (@files) { my @contents = do { open my $fh, "<$file" or die "$file: $!\n"; <$fh> }; my $subtitle = shift @contents; chomp $subtitle; my $tt = new Template { INTERPOLATE => 1, POST_CHOMP => 1, EVAL_PERL => 1, } or die "$Template::ERROR\n"; my $vars = { list => $list }; my $contents = "@contents"; my $data = ''; # Variable to store processed templates $tt->process (\$contents, $vars, \$data) or die $tt->error; # Re-initialised with static variables from YAML $vars = $static; $vars->{subtitle} = $subtitle; $vars->{contents} = $data; my $output = ''; # Variable to store the complete page $tt->process ('template.html', $vars, \$output) or die $tt->error; # Save the page to a html file $file =~ s/src\/(.+)\.html$/html\/$1.html/; open HTML, ">$file"; print HTML $output; close HTML; }