ディレクトリの中に写真をぶちこみ、「Lightbox JS v2.0」で一度にスライドショーとして見えるようにしたい。手書きでパスを書かずに。ということでTemplate Toolkitを使って、HTMLを生成すればOK。 以下、HTMLを生成するPerl。
#!/usr/bin/perl
use strict;
use File::Find;
use Template;
use IO::File;
use Encode;
my @directories = qw/photos/;
my @photos;
find(\&wanted, @directories);
sub wanted{
if(m/.*jpg$/i){
my $path = $File::Find::dir . '/' . $_;
warn "$path\n";
push(@photos, $path);
}
}
my $tt = Template->new;
my $html;
$tt->process('index.tt',{photos=>\@photos},\$html) || die $tt->error(), "\n";
my $io = IO::File->new('index.html', 'w');
$io->print(encode("utf-8",$html));
$io->close;
以下、ttの例
[% SET title = 'hoge' %]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja">
<head>
<title>[% title %]</title>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js?load=effects" type="text/javascript"></script>
<script src="js/lightbox.js" type="text/javascript"></script>
<style type="text/css">
body{ color: #333; font: 13px 'Lucida Grande', Verdana, sans-serif; }
</style>
</head>
<body>
<h1>[% title %]</h1>
<h2>写真</h2>
[% FOREACH photo = photos %]
<a href="[% photo %]" rel="lightbox[roadtrip]"><img src="[% photo %]" alt="" width="120px"></a>
[%- END -%]
</body>
</html>

