<html>
<head>
<meta name=viewport content="width=device-width initial-scale=1.0">
- <script type="text/javascript" src="<% "$STATICURL/tgal.js" |u %>" defer></script>
- <link rel=stylesheet type=text/css href="<% "$STATICURL/tgal.css" |u %>">
+ <script type="text/javascript" src="<% "$STATICURL/tgal.js" |hu %>" defer></script>
+ <link rel=stylesheet type=text/css href="<% "$STATICURL/tgal.css" |hu %>">
<% $head %>\
<title><% $title %></title>
</head>
%###-------------------------------------------------------------------------
<%def .contact>\
<%perl>
- unless ($r->path_info =~ m!/$!) {
- $m->redirect(join_paths($SCRIPTURL, $path) . "/");
- }
+ unless ($r->path_info =~ m!/$!)
+ { $m->redirect(join_paths($SCRIPTURL, $path) . "/"); }
+
my $real = join_paths $IMGROOT, $path;
my $url = join_paths $SCRIPTURL, $path;
my ($dd, $ff, $ii) = listdir $real;
urlencode "$SCRIPTURL/$uplink";
}
(my $nosl = $path) =~ s!/$!!;
+
+ my @size = ("smallthumb", "medthumb", "bigthumb");
+ my %tn;
+ my %count;
+ for my $f (@$ff) {
+ my $img = TrivGal::Image->new($path . $f->name);
+ for my $size (@size) { $tn{$f}{$size} = $img->scale($size); }
+ }
+ for my $d (@$dd) {
+ my $p = join_paths $path, $d->name;
+ my ($ddd, $fff, $iii);
+ ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
+
+ my $count = "";
+ $count .= scalar(@$ddd) . "/" if @$ddd;
+ $count .= scalar(@$fff) if @$fff;
+ $count{$d} = $count;
+
+ DIR: for (;;) {
+ if (defined $iii) {
+ my $index = join_paths $p, $iii->name;
+ my $img = TrivGal::Image->new($index);
+ for my $size (@size) { $tn{$d}{$size} = $img->scale($size); }
+ last DIR;
+ }
+ if (!@$ddd) { $tn{$d} = undef; last DIR; }
+ $p = join_paths $p, $ddd->[0]->name;
+ ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
+ }
+ }
</%perl>
%
-<&| .html, title => "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"),
+<&| .html, title =>
+ "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"),
head => $links &>
-<& .breadcrumbs, what => "Folder", path => $path &>
+<&| .breadcrumbs, what => "Folder", path => $path &>
+ <div class="menu">
+ <a href="<% "$SCRIPTURL/" . substr($path, 0, -1) . ".zip" |hu %>">[zip]</a>
+ </div>
+</&>
%
% my $note = contents "$IMGROOT/$path/.tgal-note.html";
% if (defined $note) {
%
% if (@$dd) {
<h2>Subfolders</h2>
-<div class=gallery>
-% for my $d (@$dd) {
-% my ($ddd, $fff, $iii) = listdir $real . "/" . $d->name;
-% my $tn;
-% if ($iii) { $tn = join_paths $path, $d->name . "/" . $iii->name; }
-% else { $tn = undef; }
- <& .thumbnail, target => $d->name . "/", img => $tn,
- caption => $m->interp->apply_escapes($d->name, "h"),
- comment => $d->comment &>\
-% }
+% for my $size (@size) {
+<div class="gallery <% $size %>">
+% for my $d (@$dd) {
+ <& .thumbnail, target => $d->name, comment => $d->comment,
+ tn => $tn{$d}{$size}, size => $size,
+ caption =>
+ $m->interp->apply_escapes($d->name, "h") .
+ " [$count{$d}]" &>\
+% }
</div>
+% }
% }
%
% if (@$ff) {
<h2>Images</h2>
-<div class=gallery>
-% for my $f (@$ff) {
- <& .thumbnail, target => $f->name, img => $path . $f->name,
- caption => $m->interp->apply_escapes($f->name, "h"),
- comment => $f->comment &>\
-% }
+% for my $size (@size) {
+<div class="gallery <% $size %>">
+% for my $f (@$ff) {
+ <& .thumbnail, target => $f->name, comment => $f->comment,
+ tn => $tn{$f}{$size}, size => $size,
+ caption => $m->interp->apply_escapes($f->name, "h") &>\
+% }
</div>
+% }
% }
%
<div class=fill></div>
<& .footer, path => $path &>
</&>
+%
+<%args>
+ $path
+</%args>
+</%def>
+%
+%###-------------------------------------------------------------------------
+<%def .zip>\
+<%perl>
+ my $st = stat "$IMGROOT/$path";
+ if (!$st) { $m->comp(".not-found", path => $path); return; }
+ my $zip = "$TMP/t$$-download.zip";
+ my $err = "$TMP/t$$-download.stderr";
+ my $kid = fork;
+ if (!$kid) {
+ untie *STDIN; open STDIN, "</dev/null";
+ untie *STDOUT; open STDOUT, ">/dev/null";
+ untie *STDERR; open STDERR, ">", $err;
+ chdir "$IMGROOT/$path";
+ exec "zip", "-qr", $zip, ".";
+ exit 127;
+ }
+ waitpid $kid, 0;
+</%perl>
+%
+% if ($?) {
+<&| .html, title => "Zip failed (rc = $?)" &>
+<pre>
+<%perl>
+ open my $f, "<", $err;
+ my $buf;
+ while (read $f, $buf, 16384) { $m->print($buf); }
+</%perl>
+</pre>
+</&>
+% } else {
+<%perl>
+ $r->content_type("application/zip");
+ open my $f, "<", $zip; binmode $f;
+ my $buf;
+ while (read $f, $buf, 16384) { $m->print($buf); }
+</%perl>
+% }
+%
+<%perl>
+ eval { unlink $zip; };
+ eval { unlink $err; };
+</%perl>
+
%
<%args>
$path
<%def .image>\
<%perl>
my ($dir, $base, $ext) = split_path $path;
+
+ if (defined $scale) {
+ my $img = TrivGal::Image->new($path);
+ $m->redirect($img->scale($scale, 1));
+ }
+
my $real = join_paths $IMGROOT, $path;
my $url = join_paths $IMGURL, $path;
my $realdir = join_paths $IMGROOT, $dir;
my $urldir = join_paths $SCRIPTURL, $dir;
my ($dd, $ff, $ii) = listdir $realdir;
- my $vw = scaled "view", $path;
+ my @thumbsz = qw{smallthumb medthumb bigthumb};
+ my @imgsz = sort { $SIZE{$a} <=> $SIZE{$b} } keys %SIZE;
+ my ($wd, $ht, $max);
+ my %tn;
+ my %vw;
my $fi = undef;
- FILE: for (my $i = 0; $i < @$ff; $i++)
- { if ($ff->[$i]->name eq "$base$ext") { $fi = $i; last FILE; } }
+ FILE: for (my $i = 0; $i < @$ff; $i++) {
+ my $f = $ff->[$i];
+ my $img = TrivGal::Image->new(join_paths $dir, $f->name);
+ for my $sz (@thumbsz) { $tn{$f->name}{$sz} = $img->scale($sz); }
+ if ($ff->[$i]->name eq "$base$ext") {
+ $fi = $i;
+ ($wd, $ht) = ($img->wd, $img->ht);
+ $max = $img->sz;
+ SIZE: for my $sc (@imgsz) {
+ my $sz = $SIZE{$sc};
+ last SIZE if $max < $sz;
+ $vw{$sc} = $img->scale($sc);
+ }
+ }
+ }
defined $fi or die "image not found in its folder?";
my $this = $ff->[$fi];
}
my $links = "";
- my $pre =
- urlencode join_paths $SCRIPTURL, $dir;
+ my $pre = urlencode join_paths $SCRIPTURL, $dir;
for my $rel (qw{up first prev next last}) {
- exists $link{$rel} and
- $links .= sprintf " <link rel=%s href=\"%s\">\n",
- $rel, urlencode "$pre/$link{$rel}";
+ $links .= sprintf " <link rel=%s href=\"%s\">\n", $rel,
+ urlencode "$pre/$link{$rel}"
+ if exists $link{$rel};
}
</%perl>
%
%
<div class=viewnav>
% if ($link{prev}) {
- <div class=prev><a class=prev href="<% "$pre/$link{prev}" |u %>">‹</a></div>
+ <div class=prev>
+ <a class=nav title="Previous image" href="<% "$pre/$link{prev}" |hu %>">
+ <svg width="50" height="80" viewBox="-25 -40 50 80">
+ <path class="fg" stroke="none"
+ d="m+1,0 +6,-11 -2,-1 -12,+12 +12,+12 +2,-1 z"/>
+ </svg>
+ </a>
+ </div>
% }
<a class=view href="<% $url |h %>">
- <img src="<% $vw |h %>">
+ <picture>
+% my ($hoff, $voff) = (60, 480);
+% SIZE: for (my $i = 0; $i < @imgsz; $i++) {
+% my $scale = $imgsz[$i];
+% last SIZE unless exists $vw{$scale};
+% my $scsz = $SIZE{$scale};
+% my $f = $scsz/$max;
+% my ($thiswd, $thisht) = map int, ($f*$wd + $hoff, $f*$ht + $voff);
+ <source srcset="<% $vw{$scale} |h %>"
+ media="(max-width: <% $thiswd %>px) or (max-height: <% $thisht %>px)">
+% }
+ <img src="<% "$IMGURL/$path" |hu %>">
+ </picture>
</a>
% if ($link{next}) {
- <div class=next><a class=next href="<% "$pre/$link{next}" |u %>">›</a></div>
+ <div class=next>
+ <a class=nav title="Next image" href="<% "$pre/$link{next}" |hu %>">
+ <svg width="50" height="80" viewBox="-25 -40 50 80">
+ <path class="fg" stroke="none"
+ d="m-1,0 -6,-11 +2,-1 +12,+12 -12,+12 -2,-1 z"/>
+ </svg>
+ </a>
+ </div>
% }
</div>
%
-<div class=thumbstrip>
-% for my $f (@$ff) {
- <& .thumbnail, target => $f->name, img => $dir . "/" . $f->name,
+% for my $size (qw{smallthumb medthumb bigthumb}) {
+<div class="thumbstrip <% $size %>">
+% for my $f (@$ff) {
+ <& .thumbnail, target => $f->name,
+ tn => $tn{$f->name}{$size}, size => $size,
caption => $m->interp->apply_escapes($f->name, "h"),
- focus => $f->name eq "$base$ext" &>\
-% }
+ focus => $f eq $this &>\
+% }
</div>
+% }
<& .footer, path => $dir &>
</&>
%
<%args>
$path
+ $scale => undef
</%args>
</%def>
%
% if (!@p) {
[top]
% } else {
-<a href="<% $SCRIPTURL |u %>/">[top]</a> / \
+<a href="<% $SCRIPTURL |hu %>/">[top]</a> / \
% STEP: for my $p (@p) {
% if (defined $prev) {
% $pp .= "$prev/";
-<a href="<% join_paths($SCRIPTURL, $pp) |u %>/">\
+<a href="<% join_paths($SCRIPTURL, $pp) |hu %>/">\
<% $prev %></a> / \
% }
% $prev = $p;
% }
<% $prev %>\
% }
+% if ($m->has_content) {
+
+<% $m->content %>\
+% }
</h1>
<%args>
$what
%
%###-------------------------------------------------------------------------
<%def .thumbnail>\
-% my $tn;
-% if (defined $img) { $tn = scaled "thumb", $img; }
-% else { $tn = "$STATICURL/folder.svg"; }
+% $tn //= "$STATICURL/folder.svg";
% if ($focus) {
- <div class=pic id=focusthumb>
- <img class=thumb src="<% $tn |u %>">
- <div class=caption><span class=name><% $caption %></span></div>
+ <figure class="thumb focusthumb <% $size %>">
+ <img class="thumb <% $size %>" loading=lazy src="<% $tn |h %>">
+ <figcaption><span class=name><% $caption %></span></figcaption>
% } else {
- <div class=pic>
- <a class=pic href="<% $target |u %>">
- <img class=thumb src="<% $tn |u %>">
- <div class=caption>
+ <figure class="thumb <% $size %>">
+ <a class=thumb href="<% $target |hu %>">
+ <img class="thumb <% $size %>" loading=lazy src="<% $tn |h %>">
+ <figcaption>
<span class=name><% $caption %></span>
% if (defined $comment) {
<span class=comment><% $comment %></span>
% }
- </div>
+ </figcaption>
</a>
% }
- </div>
+ </figure>
%
<%args>
$target
- $img
+ $tn
+ $size
$caption
$comment => undef
$focus => 0
</%perl>
<div class=footer>
<div class=footitem>
- <a href="https://www.gnu.org/licenses/agpl-3.0.en.html"><img class=licence src="<% "$STATICURL/agpl.png" |u %>"></a>
+ <a href="https://www.gnu.org/licenses/agpl-3.0.en.html"><img class=licence src="<% "$STATICURL/agpl.png" |hu %>"></a>
Trivial Gallery, copyright © 2021 Mark Wooding.
Free software: you can modify it and/or redistribute it under the
terms of the
- <a href="https://www.gnu.org/licenses/agpl-3.0.en.html">GNU Affero
+ <a rel=license href="https://www.gnu.org/licenses/agpl-3.0.en.html">GNU Affero
General Public License version 3</a>.
- Browse or download
- the <a href="https://git.distorted.org.uk/~mdw/tgal/">source code</a>.
+ Browse or download the <a href="<% $SRCURL %>">source code</a>.
</div>
% my $user =
% find_covering_file $IMGROOT, $path, ".tgal-footer.html";
%###-------------------------------------------------------------------------
<%once>
use autodie;
-use Data::Dumper;
use File::stat;
use TrivGal;
my $path = $m->dhandler_arg;
my $st = stat "$IMGROOT/$path";
my $comp;
- if (!$st) { $comp = ".not-found"; }
+ if (!$st) {
+ $comp = ".not-found";
+ if ($path =~ /^ (.*) (\.(?: zip)) $/x) {
+ $st = stat "$IMGROOT/$1";
+ if ($st) { $path = $1; $comp = $2; }
+ }
+ }
elsif (-d $st) { $comp = ".contact"; }
elsif (-f $st) { $comp = ".image"; }
else { $comp = ".not-found"; }
- $m->comp($comp, path => $path);
+ $r->header_out("X-AGPL-Source" => $SRCURL);
+ $m->comp($comp, path => $path, %ARGS);
</%init>
%
%###----- That's all, folks -------------------------------------------------