diff options
author | Eric Wong <e@80x24.org> | 2017-02-09 01:37:03 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-02-09 01:37:03 +0000 |
commit | d9563ea5516e8e786debf223e10ec11695aee9d7 (patch) | |
tree | a0842b1ee0953bc8e65d21d5d96432f41973adb7 /lib/PublicInbox/RepoRoot.pm | |
parent | fb9ed5324ec7de9420956840ba9a6585b81e8231 (diff) | |
download | public-inbox-d9563ea5516e8e786debf223e10ec11695aee9d7.tar.gz |
We'll still be keeping "repobrowse" for the public API for use with .psgi files, but shortening the name means less typing and we may have command-line tools, too.
Diffstat (limited to 'lib/PublicInbox/RepoRoot.pm')
-rw-r--r-- | lib/PublicInbox/RepoRoot.pm | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/PublicInbox/RepoRoot.pm b/lib/PublicInbox/RepoRoot.pm new file mode 100644 index 00000000..9ab25b97 --- /dev/null +++ b/lib/PublicInbox/RepoRoot.pm @@ -0,0 +1,71 @@ +# Copyright (C) 2016 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> + +# displays the root '/' where all the projects lie +package PublicInbox::RepoRoot; +use strict; +use warnings; +use base qw(PublicInbox::RepoBase); +use PublicInbox::Hval qw(utf8_html); + +sub call { + my ($self, $rconfig) = @_; + sub { + my ($res) = @_; # PSGI callback + my @h = ('Content-Type', 'text/html; charset=UTF-8'); + my $fh = $res->([200, \@h]); + repobrowse_index($fh, $rconfig); + $fh->close; + } +} + +sub repobrowse_index { + my ($fh, $rconfig) = @_; + my $title = 'repobrowse index'; + $fh->write("<html><head><title>$title</title>" . + PublicInbox::Hval::STYLE . + "</head><body><pre><b>$title</b>"); + + # preload all groups + foreach my $k (sort keys %$rconfig) { + $k =~ /\Arepo\.(.+)\.path\z/ or next; + my $repo_path = $1; + $rconfig->lookup($repo_path); # insert into groups + } + + my $groups = $rconfig->{-groups}; + if (scalar(keys %$groups) > 2) { # default has '-none' + '-hidden' + $fh->write("\n\n<b>uncategorized</b></pre>". + "<table\nsummary=repoindex>"); + } else { + $fh->write("</pre><table\nsummary=repoindex>"); + } + foreach my $repo_path (sort @{$groups->{-none}}) { + my $r = $rconfig->lookup($repo_path); + my $p = PublicInbox::Hval->utf8($r->{repo}); + my $l = $p->as_html; + $p = $p->as_path; + $fh->write(qq(<tr><td><tt><a\nhref="$p">$l</a></tt></td>) . + "<td><tt> $r->{desc_html}</tt></td></tr>"); + } + + foreach my $group (keys %$groups) { + next if $group =~ /\A-(?:none|hidden)\z/; + my $g = utf8_html($group); + $fh->write("<tr><td><pre> </pre></td></tr>". + "<tr><td><pre><b>$g</b></pre></tr>"); + foreach my $repo_path (sort @{$groups->{$group}}) { + my $r = $rconfig->lookup($repo_path); + my $p = PublicInbox::Hval->utf8($r->{repo}); + my $l = $p->as_html; + $p = $p->as_path; + $fh->write('<tr><td><tt> ' . + qq(<a\nhref="$p">$l</a></tt></td>) . + "<td><tt> $r->{desc_html}</tt></td></tr>"); + } + } + + $fh->write('</table></body></html>'); +} + +1; |