Package: llgal
Version: 0.13.17-2
Severity: wishlist
Tags: patch

Dear Maintainer,

When the gallery consists of a lot of images, opening single index.html linking 
to
all of them causes a lot of load on both client and server.

To avoid this I would like to suggest splitting this index page into multiple 
pages.

Attached is the patch I wrote to paginate the output by amount of images 
specified
in the config file. Its template work is rather kludgy, but it works.

Please tell me whether you are interested in it and what else do I need to fix 
if so.

Best regards,
Ivan

-- System Information:
Debian Release: 7.5
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 3.13-0.bpo.1-686-pae (SMP w/4 CPU cores)
Locale: LANG=ru_RU.UTF-8, LC_CTYPE=ru_RU.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages llgal depends on:
ii  imagemagick             8:6.7.7.10-5+deb7u3
ii  libimage-size-perl      3.232-1
ii  liblocale-gettext-perl  1.05-7+b1
ii  liburi-perl             1.60-1
ii  perl                    5.14.2-21+deb7u1

Versions of packages llgal recommends:
pn  libimage-exiftool-perl  <none>

llgal suggests no packages.

-- no debconf information
Description: add pagination support
 Add new option, img_per_page, which allows to split the main index.html into
 a number of files, each containing no more than img_per_page frames.
 .
 Author: Ivan Krylov <[email protected]>

Index: llgal-0.13.17/llgal.in
===================================================================
--- llgal-0.13.17.orig/llgal.in	2014-07-11 14:33:13.000000000 +0400
+++ llgal-0.13.17/llgal.in	2014-07-11 14:34:18.892230745 +0400
@@ -1907,17 +1907,24 @@
     my @headers = @{$gallery->{headers}} ;
     my @footers = @{$gallery->{footers}} ;
 
+    my $img_per_page = $opts->{img_per_page};
+
+    my $current = 0;
+
     # find the indextemplate
     my $indextemplate = (Llgal::Templates::find_template_file ($self, $opts, $opts->{indextemplate_filename}, 1))
 	. "/$opts->{indextemplate_filename}" ;
     $messages->print ("Using '$indextemplate' as HTML index template.\n") ;
 
+while ($current <= ($img_per_page ? int(@entries/$img_per_page) : 0)) {
+    $messages->print("Writing page #$current\n");
     # open the template and the destination
-    $messages->print ("Creating the $opts->{index_filename}.$opts->{www_extension} file: ") ;
+    my $filename = "$opts->{index_filename}".($current?".$current":"").".$opts->{www_extension}";
+    $messages->print ("Creating the $filename file: ") ;
     open(IXR, "$indextemplate")
 	or die "Can't open the index template file '$indextemplate' ($!).\n" ;
-    open(IXW, ">$self->{destination_dir}$opts->{index_filename}.$opts->{www_extension}")
-	or die "Can't create main $opts->{index_filename}.$opts->{www_extension} file ($!).\n" ;
+    open(IXW, ">$self->{destination_dir}$filename")
+	or die "Can't create main $filename file ($!).\n" ;
 
     # headers
     my $line ;
@@ -1950,11 +1957,11 @@
 
     # output thumbnails
     my $forced_width_warning = 0 ;
-    my $i = 0 ;
+    my $i = $current*$img_per_page;
     $messages->init_percentage (scalar @entries) ;
 
-    while ($i < scalar @entries) {
-	my $entry = $entries[$i] ;
+    IMAGE: while ($i < ($img_per_page ? $img_per_page*($current+1) : @entries)) {
+	my $entry = $entries[$i] or last IMAGE; # then loop terminates because $current > int(@entries/$img_per_page)
 	my $type = $entry->{type} ;
 
 	if ($type == $TYPE_LINE or $type == $TYPE_BREAK) {
@@ -2178,9 +2185,19 @@
 		$line =~ s/$field/$common_fields->{$field}/g ;
 	    }
 
+            next if !$img_per_page and $line =~ m[<!--(NEXT|PREV)-PAGE(-TEXT)?-->];
+
+	    $line =~ s[<!--(NEXT|PREV)-PAGE(-TEXT)?-->][
+		        my $number = ($current + {NEXT=>+1,PREV=>-1}->{$1}) % (int(@entries/$img_per_page) + 1);
+			my $link = $opts->{index_filename} . ($number ? ".$number" : "") . ".$opts->{www_extension}";
+			$2 ? {NEXT=>">>",PREV=>"<<"}->{$1}.$number
+			   : $link;
+		      ]exg;
+
 	    print IXW "$line" ;
 	}
     }
+    $current++;
     close IXW ;
     close IXR ;
 
@@ -2189,6 +2206,7 @@
     $messages->warning ("Row width max ($opts->{pixels_per_row}) too low for one single thumbnail. "
 	. "Forced $forced_width_warning time". ($forced_width_warning>1?"s":"") .".")
 	if $forced_width_warning ;
+    }
 }
 
 #######################################################################
Index: llgal-0.13.17/lib/Llgal/Config.pm
===================================================================
--- llgal-0.13.17.orig/lib/Llgal/Config.pm	2014-07-11 13:28:10.356551839 +0400
+++ llgal-0.13.17/lib/Llgal/Config.pm	2014-07-11 14:33:13.000000000 +0400
@@ -99,6 +99,7 @@
     FIL_link_to_target => $OPT_IS_NUMERIC,
     DIR_link_to_target => $OPT_IS_NUMERIC,
     LNK_link_to_target => $OPT_IS_NUMERIC,
+    img_per_page => $OPT_IS_NUMERIC,
 # Slides
     make_no_slides => $OPT_IS_NUMERIC,
     make_slide_filename_from_filename => $OPT_IS_NUMERIC,
@@ -302,6 +303,8 @@
 	FIL_link_to_target => 0,
 	DIR_link_to_target => 0,
 	LNK_link_to_target => 0,
+# images per page, 0 means no pagination
+	img_per_page => 0,
 
 # Slides
 # make no slides, just thumbnail links to images (-s)
Index: llgal-0.13.17/data/indextemplate.html
===================================================================
--- llgal-0.13.17.orig/data/indextemplate.html	2007-03-24 03:58:59.000000000 +0300
+++ llgal-0.13.17/data/indextemplate.html	2014-07-11 14:33:13.000000000 +0400
@@ -26,6 +26,12 @@
 
     <!--FOOTERS-->
 
+    <p class="center">
+      <a href="<!--PREV-PAGE-->"><!--PREV-PAGE-TEXT--></a>
+      &nbsp;&nbsp;&nbsp;
+      <a href="<!--NEXT-PAGE-->"><!--NEXT-PAGE-TEXT--></a>
+    </p>
+
     <p class="small"><!--CREDITS--></p>
 
   </body>

Reply via email to