X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=gal2%2Fgal-cache;h=7d581a632dd21d8dd2a29dab4bd7f90b1a76345d;hb=dca33bff0ad0aff7e0f995c45c2b456cf525ac57;hp=426335e5023f6ae98be8888246f0eaa30690e894;hpb=b89f977dc5a5d785766118992aa90a7eff7b5d3b;p=gallery.git diff --git a/gal2/gal-cache b/gal2/gal-cache index 426335e..7d581a6 100755 --- a/gal2/gal-cache +++ b/gal2/gal-cache @@ -5,7 +5,8 @@ use strict; use warnings; -use lib '/home/mj/web/gal2'; +use FindBin; +use lib $FindBin::Bin; use UCW::Gallery; use Image::Magick; @@ -15,15 +16,18 @@ use File::Path; STDOUT->autoflush(1); -UCW::Gallery::LoadConfig; +my $gal = UCW::Gallery->load_config; -my $photo_dir = $UCW::Gallery::CF{'PhotoDir'}; +print "Reading gallery.list\n"; +my $orig_list = $gal->read_list('gallery.list') or die "Cannot read gallery.list: $!\n"; + +my $photo_dir = $gal->get('PhotoDir'); my $photo_meta = File::Spec->catfile($photo_dir, 'gallery.meta'); print "Reading meta-data from $photo_meta\n"; -f $photo_meta or die "Cannot load $photo_meta\n"; -my $meta = UCW::Gallery::ReadMeta($photo_meta); +my $meta = $gal->read_meta($photo_meta); -my $cache_dir = $UCW::Gallery::CF{'CacheDir'}; +my $cache_dir = $gal->get('CacheDir'); if (-d $cache_dir) { print "Deleting old cache directory: $cache_dir\n"; File::Path::remove_tree($cache_dir); @@ -31,9 +35,16 @@ if (-d $cache_dir) { print "Creating cache directory: $cache_dir\n"; File::Path::mkpath($cache_dir) or die "Unable to create $cache_dir: $!\n"; -for my $t (@{$UCW::Gallery::CF{'ThumbSizes'}}) { - my ($tw, $th) = @$t; - my $thumb_fmt = $tw . 'x' . $th; +# Construct sequence and store photo titles +$meta->{sequence} = []; +for my $f (@$orig_list) { + push @{$meta->{sequence}}, $f->{id}; + my $m = $meta->{photo}->{$f->{id}} or die; + $m->{title} = $f->{title}; +} + +for my $thumb_fmt (keys %{$gal->get('ThumbFormats')}) { + my ($tw, $th) = ($thumb_fmt =~ m{^(\d+)x(\d+)$}) or die "Cannot parse thumbnail format $thumb_fmt\n"; print "Generating $thumb_fmt thumbnails\n"; my $thumb_meta = {}; $meta->{thumb}->{$thumb_fmt} = $thumb_meta; @@ -82,4 +93,4 @@ for my $t (@{$UCW::Gallery::CF{'ThumbSizes'}}) { my $cache_meta = File::Spec->catfile($cache_dir, 'cache.meta'); print "Writing meta-data to $cache_meta\n"; -UCW::Gallery::WriteMeta($cache_meta, $meta); +$gal->write_meta($cache_meta, $meta);