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!/$!!;
88 { $tn{$f} = TrivGal::Image->new($path . $f->name); }
90 my ($ddd, $fff, $iii) = listdir $real . "/" . $d->name;
92 TrivGal::Image->new(join_paths $path, $d->name, $iii->name) :
97 <&| .html, title => "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"),
99 <& .breadcrumbs, what => "Folder", path => $path &>
101 % my $note = contents "$IMGROOT/$path/.tgal-note.html";
102 % if (defined $note) {
110 % for my $size (qw{medthumb}) {
111 <div class="gallery <% $size %>">
113 <& .thumbnail, target => $d->name . "/", comment => $d->comment,
114 img => $tn{$d}, size => $size,
115 caption => $m->interp->apply_escapes($d->name, "h") &>\
123 % for my $size (qw{medthumb}) {
124 <div class="gallery <% $size %>">
126 <& .thumbnail, target => $f->name, comment => $f->comment,
127 img => $tn{$f}, size => "bigthumb",
128 caption => $m->interp->apply_escapes($f->name, "h") &>\
134 <div class=fill></div>
135 <& .footer, path => $path &>
143 %###-------------------------------------------------------------------------
146 my ($dir, $base, $ext) = split_path $path;
147 my $real = join_paths $IMGROOT, $path;
148 my $img = TrivGal::Image->new($path);
150 if (defined $scale) { $m->redirect($img->scale($scale)); }
152 my $url = join_paths $IMGURL, $path;
153 my $realdir = join_paths $IMGROOT, $dir;
154 my $urldir = join_paths $SCRIPTURL, $dir;
155 my ($dd, $ff, $ii) = listdir $realdir;
156 my $vw = $img->scale("view");
159 FILE: for (my $i = 0; $i < @$ff; $i++)
160 { if ($ff->[$i]->name eq "$base$ext") { $fi = $i; last FILE; } }
161 defined $fi or die "image not found in its folder?";
162 my $this = $ff->[$fi];
167 $link{first} = $ff->[0]->name;
168 $link{prev} = $ff->[$fi - 1]->name;
170 if ($fi != @$ff - 1) {
171 $link{last} = $ff->[-1]->name;
172 $link{next} = $ff->[$fi + 1]->name;
177 urlencode join_paths $SCRIPTURL, $dir;
178 for my $rel (qw{up first prev next last}) {
179 exists $link{$rel} and
180 $links .= sprintf " <link rel=%s href=\"%s\">\n",
181 $rel, urlencode "$pre/$link{$rel}";
185 <&| .html, title => "Image " . $m->interp->apply_escapes($path, "h"),
187 <& .breadcrumbs, what => "Image", path => $path &>
188 % if ($this->comment) {
190 <p><% $this->comment %>
196 <div class=prev><a class=prev href="<% "$pre/$link{prev}" |u %>">‹</a></div>
198 <a class=view href="<% $url |h %>">
199 <img src="<% $vw |h %>">
202 <div class=next><a class=next href="<% "$pre/$link{next}" |u %>">›</a></div>
206 % my %img = map { $_ => TrivGal::Image->new($dir . "/" . $_->name) } @$ff;
207 % for my $size (qw{smallthumb medthumb bigthumb}) {
208 <div class="thumbstrip <% $size %>">
210 <& .thumbnail, target => $f->name, img => $img{$f}, size => $size,
211 caption => $m->interp->apply_escapes($f->name, "h"),
212 focus => $f->name eq "$base$ext" &>\
216 <& .footer, path => $dir &>
225 %###-------------------------------------------------------------------------
228 % my @p = split m!/!, $path;
235 <a href="<% $SCRIPTURL |u %>/">[top]</a> / \
236 % STEP: for my $p (@p) {
237 % if (defined $prev) {
239 <a href="<% join_paths($SCRIPTURL, $pp) |u %>/">\
240 <% $prev %></a> / \
253 %###-------------------------------------------------------------------------
256 % if (defined $img) { $tn = $img->scale($size); }
257 % else { $tn = "$STATICURL/folder.svg"; }
259 <figure class="thumb focusthumb <% $size %>">
260 <img class="thumb <% $size %>" load=lazy src="<% $tn |u %>">
261 <figcaption><span class=name><% $caption %></span></figcaption>
263 <figure class="thumb <% $size %>">
264 <a class=thumb href="<% $target |u %>">
265 <img class="thumb <% $size %>" load=lazy src="<% $tn |u %>">
267 <span class=name><% $caption %></span>
268 % if (defined $comment) {
269 <span class=comment><% $comment %></span>
286 %###-------------------------------------------------------------------------
292 <a href="https://www.gnu.org/licenses/agpl-3.0.en.html"><img class=licence src="<% "$STATICURL/agpl.png" |u %>"></a>
293 Trivial Gallery, copyright © 2021 Mark Wooding.
294 Free software: you can modify it and/or redistribute it under the
296 <a rel=license href="https://www.gnu.org/licenses/agpl-3.0.en.html">GNU Affero
297 General Public License version 3</a>.
298 Browse or download the <a href="<% $SRCURL %>">source code</a>.
301 % find_covering_file $IMGROOT, $path, ".tgal-footer.html";
302 % if (defined $user) {
313 %###-------------------------------------------------------------------------
324 my $path = $m->dhandler_arg;
325 my $st = stat "$IMGROOT/$path";
327 if (!$st) { $comp = ".not-found"; }
328 elsif (-d $st) { $comp = ".contact"; }
329 elsif (-f $st) { $comp = ".image"; }
330 else { $comp = ".not-found"; }
331 $r->header_out("X-AGPL-Source" => $SRCURL);
332 $m->comp($comp, path => $path, %ARGS);
335 %###----- That's all, folks -------------------------------------------------