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";
89 { $tn{$f} = TrivGal::Image->new($path . $f->name)->scale($size); }
91 my $p = join_paths $path, $d->name;
92 my ($ddd, $fff, $iii);
93 ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
96 my $index = join_paths $p, $iii->name;
97 $tn{$d} = TrivGal::Image->new($index)->scale($size);
100 if (!@$ddd) { $tn{$d} = undef; last DIR; }
101 $p = join_paths $p, $ddd->[0]->name;
102 ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
108 "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"),
110 <& .breadcrumbs, what => "Folder", path => $path &>
112 % my $note = contents "$IMGROOT/$path/.tgal-note.html";
113 % if (defined $note) {
121 <div class="gallery <% $size %>">
123 <& .thumbnail, target => $d->name, comment => $d->comment,
124 tn => $tn{$d}, size => $size,
125 caption => $m->interp->apply_escapes($d->name, "h") &>\
132 <div class="gallery <% $size %>">
134 <& .thumbnail, target => $f->name, comment => $f->comment,
135 tn => $tn{$f}, size => $size,
136 caption => $m->interp->apply_escapes($f->name, "h") &>\
141 <div class=fill></div>
142 <& .footer, path => $path &>
150 %###-------------------------------------------------------------------------
153 my ($dir, $base, $ext) = split_path $path;
155 if (defined $scale) {
156 my $img = TrivGal::Image->new($path);
157 $m->redirect($img->scale($scale, 1));
160 my $real = join_paths $IMGROOT, $path;
161 my $url = join_paths $IMGURL, $path;
162 my $realdir = join_paths $IMGROOT, $dir;
163 my $urldir = join_paths $SCRIPTURL, $dir;
164 my ($dd, $ff, $ii) = listdir $realdir;
165 my @thumbsz = qw{smallthumb medthumb bigthumb};
170 FILE: for (my $i = 0; $i < @$ff; $i++) {
172 my $img = TrivGal::Image->new(join_paths $dir, $f->name);
173 for my $sz (@thumbsz) { $tn{$f->name}{$sz} = $img->scale($sz); }
174 if ($ff->[$i]->name eq "$base$ext")
175 { $fi = $i; $vw = $img->scale("view"); }
177 defined $fi or die "image not found in its folder?";
178 my $this = $ff->[$fi];
183 $link{first} = $ff->[0]->name;
184 $link{prev} = $ff->[$fi - 1]->name;
186 if ($fi != @$ff - 1) {
187 $link{last} = $ff->[-1]->name;
188 $link{next} = $ff->[$fi + 1]->name;
193 urlencode join_paths $SCRIPTURL, $dir;
194 for my $rel (qw{up first prev next last}) {
195 exists $link{$rel} and
196 $links .= sprintf " <link rel=%s href=\"%s\">\n",
197 $rel, urlencode "$pre/$link{$rel}";
201 <&| .html, title => "Image " . $m->interp->apply_escapes($path, "h"),
203 <& .breadcrumbs, what => "Image", path => $path &>
204 % if ($this->comment) {
206 <p><% $this->comment %>
212 <div class=prev><a class=prev href="<% "$pre/$link{prev}" |u %>">‹</a></div>
214 <a class=view href="<% $url |h %>">
215 <img src="<% $vw |h %>">
218 <div class=next><a class=next href="<% "$pre/$link{next}" |u %>">›</a></div>
222 % for my $size (qw{smallthumb medthumb bigthumb}) {
223 <div class="thumbstrip <% $size %>">
225 <& .thumbnail, target => $f->name,
226 tn => $tn{$f->name}{$size}, size => $size,
227 caption => $m->interp->apply_escapes($f->name, "h"),
228 focus => $f eq $this &>\
232 <& .footer, path => $dir &>
241 %###-------------------------------------------------------------------------
244 % my @p = split m!/!, $path;
251 <a href="<% $SCRIPTURL |u %>/">[top]</a> / \
252 % STEP: for my $p (@p) {
253 % if (defined $prev) {
255 <a href="<% join_paths($SCRIPTURL, $pp) |u %>/">\
256 <% $prev %></a> / \
269 %###-------------------------------------------------------------------------
271 % $tn //= "$STATICURL/folder.svg";
273 <figure class="thumb focusthumb <% $size %>">
274 <img class="thumb <% $size %>" load=lazy src="<% $tn |h %>">
275 <figcaption><span class=name><% $caption %></span></figcaption>
277 <figure class="thumb <% $size %>">
278 <a class=thumb href="<% $target |u %>">
279 <img class="thumb <% $size %>" load=lazy src="<% $tn |h %>">
281 <span class=name><% $caption %></span>
282 % if (defined $comment) {
283 <span class=comment><% $comment %></span>
300 %###-------------------------------------------------------------------------
306 <a href="https://www.gnu.org/licenses/agpl-3.0.en.html"><img class=licence src="<% "$STATICURL/agpl.png" |u %>"></a>
307 Trivial Gallery, copyright © 2021 Mark Wooding.
308 Free software: you can modify it and/or redistribute it under the
310 <a rel=license href="https://www.gnu.org/licenses/agpl-3.0.en.html">GNU Affero
311 General Public License version 3</a>.
312 Browse or download the <a href="<% $SRCURL %>">source code</a>.
315 % find_covering_file $IMGROOT, $path, ".tgal-footer.html";
316 % if (defined $user) {
327 %###-------------------------------------------------------------------------
338 my $path = $m->dhandler_arg;
339 my $st = stat "$IMGROOT/$path";
341 if (!$st) { $comp = ".not-found"; }
342 elsif (-d $st) { $comp = ".contact"; }
343 elsif (-f $st) { $comp = ".image"; }
344 else { $comp = ".not-found"; }
345 $r->header_out("X-AGPL-Source" => $SRCURL);
346 $m->comp($comp, path => $path, %ARGS);
349 %###----- That's all, folks -------------------------------------------------