diff options
author | Eric Wong <e@80x24.org> | 2016-12-13 21:56:39 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-12-14 00:22:55 +0000 |
commit | 00488f0cfe9f81d04cd65d09ea783e860c937401 (patch) | |
tree | 24e4d9282d5e7098fc6cbdcc9d5615c46513661f /lib/PublicInbox/RepobrowseRoot.pm | |
parent | f9d4f28d9761011d3c7ffad9e2c9d1e54b65c519 (diff) | |
parent | 6cdb0221d18b2caed4d0caebf7c20d6eb159497d (diff) | |
download | public-inbox-00488f0cfe9f81d04cd65d09ea783e860c937401.tar.gz |
* origin/repobrowse: (98 commits) t/repobrowse_git_httpd.t: ensure signature exists for split t/repobrowse_git_tree.t: fix test for lack of bold repobrowse: fix alignment of gitlink entries repobrowse: show invalid type for tree views repobrowse: do not bold directory names in tree view repobrowse: reduce checks for response fh repobrowse: larger, short-lived buffer for reading patches repobrowse: reduce risk of callback reference cycles repobrowse: snapshot support for cgit compatibility test: disable warning for Plack::Test::Impl repobrowse: avoid confusing linkification for "diff" repobrowse: git commit view uses pi-httpd.async repobrowse: more consistent variable naming for /commit/ repobrowse: show roughly equivalent "diff-tree" invocation repobrowse: reduce local variables for state management repobrowse: summary handles multiple README types repobrowse: remove bold decorations from diff view repobrowse: common git diff parsing code repobrowse: implement diff view for compatibility examples/repobrowse.psgi: disable Chunked response by default ...
Diffstat (limited to 'lib/PublicInbox/RepobrowseRoot.pm')
-rw-r--r-- | lib/PublicInbox/RepobrowseRoot.pm | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/PublicInbox/RepobrowseRoot.pm b/lib/PublicInbox/RepobrowseRoot.pm new file mode 100644 index 00000000..fda96437 --- /dev/null +++ b/lib/PublicInbox/RepobrowseRoot.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::RepobrowseRoot; +use strict; +use warnings; +use base qw(PublicInbox::RepobrowseBase); +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; |