public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob c04c23c554a87e38fcb8df0532fb96af84240406 2020 bytes (raw)
$ git show repobrowse:lib/PublicInbox/RepoRoot.pm	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git