3 %### Main output for Trivial Gallery.
5 %### (c) 2021 Mark Wooding
8 %###----- Licensing notice --------------------------------------------------
10 %### This file is part of Trivial Gallery.
12 %### Trivial Gallery is free software: you can redistribute it and/or modify
13 %### it under the terms of the GNU Affero General Public License as
14 %### published by the Free Software Foundation; either version 3 of the
15 %### License, or (at your option) any later version.
17 %### Trivial Gallery is distributed in the hope that it will be useful, but
18 %### WITHOUT ANY WARRANTY; without even the implied warranty of
19 %### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 %### Affero General Public License for more details.
22 %### You should have received a copy of the GNU Affero General Public
23 %### License along with Trivial Gallery. If not, see
24 %### <https://www.gnu.org/licenses/>.
26 %###-------------------------------------------------------------------------
28 % $r->content_type("text/html; charset=\"utf-8\"");
31 Trivial Gallery, copyright © 2021 Mark Wooding.
32 Free software: you can redistribute it and/or modify it under the terms
33 of the GNU Affero General Public License.
37 <meta name=viewport content="width=device-width initial-scale=1.0">
38 <script type="text/javascript" src="<% "$STATICURL/tgal.js" |u %>" defer></script>
39 <link rel=stylesheet type=text/css href="<% "$STATICURL/tgal.css" |u %>">
41 <title><% $title %></title>
54 %###-------------------------------------------------------------------------
56 <&| .html, title => "Not found" &>
58 Failed to find ‘<% $path |h %>’.
67 %###-------------------------------------------------------------------------
70 unless ($r->path_info =~ m!/$!)
71 { $m->redirect(join_paths($SCRIPTURL, $path) . "/"); }
73 my $real = join_paths $IMGROOT, $path;
74 my $url = join_paths $SCRIPTURL, $path;
75 my ($dd, $ff, $ii) = listdir $real;
78 if ($path eq "" || $path eq "/") { $uplink = undef; }
80 ($uplink = $path) =~ s![^/]*/$!!;
81 $links .= sprintf " <link rel=up href=\"%s\">\n",
82 urlencode "$SCRIPTURL/$uplink";
84 (my $nosl = $path) =~ s!/$!!;
86 my $size = "medthumb";
90 { $tn{$f} = TrivGal::Image->new($path . $f->name)->scale($size); }
92 my $p = join_paths $path, $d->name;
93 my ($ddd, $fff, $iii);
94 ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
95 $nd{$d} = @$ddd; $nf{$d} = @$fff;
98 my $index = join_paths $p, $iii->name;
99 $tn{$d} = TrivGal::Image->new($index)->scale($size);
102 if (!@$ddd) { $tn{$d} = undef; last DIR; }
103 $p = join_paths $p, $ddd->[0]->name;
104 ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
110 "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"),
112 <& .breadcrumbs, what => "Folder", path => $path &>
114 % my $note = contents "$IMGROOT/$path/.tgal-note.html";
115 % if (defined $note) {
123 <div class="gallery <% $size %>">
126 % $count .= "$nd{$d}/" if $nd{$d};
127 % $count .= "$nf{$d}" if $nf{$d};
128 <& .thumbnail, target => $d->name, comment => $d->comment,
129 tn => $tn{$d}, size => $size,
131 $m->interp->apply_escapes($d->name, "h") . " [$count]" &>\
138 <div class="gallery <% $size %>">
140 <& .thumbnail, target => $f->name, comment => $f->comment,
141 tn => $tn{$f}, size => $size,
142 caption => $m->interp->apply_escapes($f->name, "h") &>\
147 <div class=fill></div>
148 <& .footer, path => $path &>
156 %###-------------------------------------------------------------------------
159 my ($dir, $base, $ext) = split_path $path;
161 if (defined $scale) {
162 my $img = TrivGal::Image->new($path);
163 $m->redirect($img->scale($scale, 1));
166 my $real = join_paths $IMGROOT, $path;
167 my $url = join_paths $IMGURL, $path;
168 my $realdir = join_paths $IMGROOT, $dir;
169 my $urldir = join_paths $SCRIPTURL, $dir;
170 my ($dd, $ff, $ii) = listdir $realdir;
171 my @thumbsz = qw{smallthumb medthumb bigthumb};
176 FILE: for (my $i = 0; $i < @$ff; $i++) {
178 my $img = TrivGal::Image->new(join_paths $dir, $f->name);
179 for my $sz (@thumbsz) { $tn{$f->name}{$sz} = $img->scale($sz); }
180 if ($ff->[$i]->name eq "$base$ext")
181 { $fi = $i; $vw = $img->scale("view"); }
183 defined $fi or die "image not found in its folder?";
184 my $this = $ff->[$fi];
189 $link{first} = $ff->[0]->name;
190 $link{prev} = $ff->[$fi - 1]->name;
192 if ($fi != @$ff - 1) {
193 $link{last} = $ff->[-1]->name;
194 $link{next} = $ff->[$fi + 1]->name;
199 urlencode join_paths $SCRIPTURL, $dir;
200 for my $rel (qw{up first prev next last}) {
201 exists $link{$rel} and
202 $links .= sprintf " <link rel=%s href=\"%s\">\n",
203 $rel, urlencode "$pre/$link{$rel}";
207 <&| .html, title => "Image " . $m->interp->apply_escapes($path, "h"),
209 <& .breadcrumbs, what => "Image", path => $path &>
210 % if ($this->comment) {
212 <p><% $this->comment %>
218 <div class=prev><a class=prev href="<% "$pre/$link{prev}" |u %>">‹</a></div>
220 <a class=view href="<% $url |h %>">
221 <img src="<% $vw |h %>">
224 <div class=next><a class=next href="<% "$pre/$link{next}" |u %>">›</a></div>
228 % for my $size (qw{smallthumb medthumb bigthumb}) {
229 <div class="thumbstrip <% $size %>">
231 <& .thumbnail, target => $f->name,
232 tn => $tn{$f->name}{$size}, size => $size,
233 caption => $m->interp->apply_escapes($f->name, "h"),
234 focus => $f eq $this &>\
238 <& .footer, path => $dir &>
247 %###-------------------------------------------------------------------------
250 % my @p = split m!/!, $path;
257 <a href="<% $SCRIPTURL |u %>/">[top]</a> / \
258 % STEP: for my $p (@p) {
259 % if (defined $prev) {
261 <a href="<% join_paths($SCRIPTURL, $pp) |u %>/">\
262 <% $prev %></a> / \
275 %###-------------------------------------------------------------------------
277 % $tn //= "$STATICURL/folder.svg";
279 <figure class="thumb focusthumb <% $size %>">
280 <img class="thumb <% $size %>" load=lazy src="<% $tn |h %>">
281 <figcaption><span class=name><% $caption %></span></figcaption>
283 <figure class="thumb <% $size %>">
284 <a class=thumb href="<% $target |u %>">
285 <img class="thumb <% $size %>" load=lazy src="<% $tn |h %>">
287 <span class=name><% $caption %></span>
288 % if (defined $comment) {
289 <span class=comment><% $comment %></span>
306 %###-------------------------------------------------------------------------
312 <a href="https://www.gnu.org/licenses/agpl-3.0.en.html"><img class=licence src="<% "$STATICURL/agpl.png" |u %>"></a>
313 Trivial Gallery, copyright © 2021 Mark Wooding.
314 Free software: you can modify it and/or redistribute it under the
316 <a rel=license href="https://www.gnu.org/licenses/agpl-3.0.en.html">GNU Affero
317 General Public License version 3</a>.
318 Browse or download the <a href="<% $SRCURL %>">source code</a>.
321 % find_covering_file $IMGROOT, $path, ".tgal-footer.html";
322 % if (defined $user) {
333 %###-------------------------------------------------------------------------
344 my $path = $m->dhandler_arg;
345 my $st = stat "$IMGROOT/$path";
347 if (!$st) { $comp = ".not-found"; }
348 elsif (-d $st) { $comp = ".contact"; }
349 elsif (-f $st) { $comp = ".image"; }
350 else { $comp = ".not-found"; }
351 $r->header_out("X-AGPL-Source" => $SRCURL);
352 $m->comp($comp, path => $path, %ARGS);
355 %###----- That's all, folks -------------------------------------------------