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!/$!!;
87 <&| .html, title => "Folder " . $m->interp->apply_escapes($nosl || "[top]", "h"),
89 <& .breadcrumbs, what => "Folder", path => $path &>
91 % my $note = contents "$IMGROOT/$path/.tgal-note.html";
92 % if (defined $note) {
102 % my ($ddd, $fff, $iii) = listdir $real . "/" . $d->name;
104 % if ($iii) { $tn = join_paths $path, $d->name . "/" . $iii->name; }
105 % else { $tn = undef; }
106 <& .thumbnail, target => $d->name . "/", img => $tn,
107 caption => $m->interp->apply_escapes($d->name, "h"),
108 comment => $d->comment &>\
117 <& .thumbnail, target => $f->name, img => $path . $f->name,
118 caption => $m->interp->apply_escapes($f->name, "h"),
119 comment => $f->comment &>\
124 <div class=fill></div>
125 <& .footer, path => $path &>
133 %###-------------------------------------------------------------------------
136 my ($dir, $base, $ext) = split_path $path;
137 my $real = join_paths $IMGROOT, $path;
138 my $url = join_paths $IMGURL, $path;
139 my $realdir = join_paths $IMGROOT, $dir;
140 my $urldir = join_paths $SCRIPTURL, $dir;
141 my ($dd, $ff, $ii) = listdir $realdir;
142 my $vw = scaled "view", $path;
145 FILE: for (my $i = 0; $i < @$ff; $i++)
146 { if ($ff->[$i]->name eq "$base$ext") { $fi = $i; last FILE; } }
147 defined $fi or die "image not found in its folder?";
148 my $this = $ff->[$fi];
153 $link{first} = $ff->[0]->name;
154 $link{prev} = $ff->[$fi - 1]->name;
156 if ($fi != @$ff - 1) {
157 $link{last} = $ff->[-1]->name;
158 $link{next} = $ff->[$fi + 1]->name;
163 urlencode join_paths $SCRIPTURL, $dir;
164 for my $rel (qw{up first prev next last}) {
165 exists $link{$rel} and
166 $links .= sprintf " <link rel=%s href=\"%s\">\n",
167 $rel, urlencode "$pre/$link{$rel}";
171 <&| .html, title => "Image " . $m->interp->apply_escapes($path, "h"),
173 <& .breadcrumbs, what => "Image", path => $path &>
174 % if ($this->comment) {
176 <p><% $this->comment %>
182 <div class=prev><a class=prev href="<% "$pre/$link{prev}" |u %>">‹</a></div>
184 <a class=view href="<% $url |h %>">
185 <img src="<% $vw |h %>">
188 <div class=next><a class=next href="<% "$pre/$link{next}" |u %>">›</a></div>
192 <div class=thumbstrip>
194 <& .thumbnail, target => $f->name, img => $dir . "/" . $f->name,
195 caption => $m->interp->apply_escapes($f->name, "h"),
196 focus => $f->name eq "$base$ext" &>\
199 <& .footer, path => $dir &>
207 %###-------------------------------------------------------------------------
210 % my @p = split m!/!, $path;
217 <a href="<% $SCRIPTURL |u %>/">[top]</a> / \
218 % STEP: for my $p (@p) {
219 % if (defined $prev) {
221 <a href="<% join_paths($SCRIPTURL, $pp) |u %>/">\
222 <% $prev %></a> / \
235 %###-------------------------------------------------------------------------
238 % if (defined $img) { $tn = scaled "thumb", $img; }
239 % else { $tn = "$STATICURL/folder.svg"; }
241 <div class=pic id=focusthumb>
242 <img class=thumb src="<% $tn |u %>">
243 <div class=caption><span class=name><% $caption %></span></div>
246 <a class=pic href="<% $target |u %>">
247 <img class=thumb src="<% $tn |u %>">
249 <span class=name><% $caption %></span>
250 % if (defined $comment) {
251 <span class=comment><% $comment %></span>
267 %###-------------------------------------------------------------------------
273 <a href="https://www.gnu.org/licenses/agpl-3.0.en.html"><img class=licence src="<% "$STATICURL/agpl.png" |u %>"></a>
274 Trivial Gallery, copyright © 2021 Mark Wooding.
275 Free software: you can modify it and/or redistribute it under the
277 <a href="https://www.gnu.org/licenses/agpl-3.0.en.html">GNU Affero
278 General Public License version 3</a>.
280 the <a href="https://git.distorted.org.uk/~mdw/tgal/">source code</a>.
283 % find_covering_file $IMGROOT, $path, ".tgal-footer.html";
284 % if (defined $user) {
295 %###-------------------------------------------------------------------------
307 my $path = $m->dhandler_arg;
308 my $st = stat "$IMGROOT/$path";
310 if (!$st) { $comp = ".not-found"; }
311 elsif (-d $st) { $comp = ".contact"; }
312 elsif (-f $st) { $comp = ".image"; }
313 else { $comp = ".not-found"; }
314 $m->comp($comp, path => $path);
317 %###----- That's all, folks -------------------------------------------------