X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWwwStream.pm;h=59edad5de5bd4238212b45f06c2b174f4e6ed7ae;hb=0aa46753c3b033aee1b4de5f358c33b912febe07;hp=c960edc52fdc545503e9d73ec8444f04c812e62e;hpb=5b96edcb1e0d825244d5a12470e0f32526262611;p=public-inbox.git
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index c960edc5..59edad5d 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2021 all contributors
+# Copyright (C) all contributors
# License: AGPL-3.0+
#
# HTML body stream for which yields getline+close methods for
@@ -18,7 +18,7 @@ https://public-inbox.org/public-inbox.git) ];
sub base_url ($) {
my $ctx = shift;
- my $base_url = $ctx->{ibx}->base_url($ctx->{env});
+ my $base_url = ($ctx->{ibx} // $ctx->{git})->base_url($ctx->{env});
chop $base_url; # no trailing slash for clone
$base_url;
}
@@ -27,17 +27,20 @@ sub init {
my ($ctx, $cb) = @_;
$ctx->{cb} = $cb;
$ctx->{base_url} = base_url($ctx);
+ $ctx->{-res_hdr} = [ 'Content-Type' => 'text/html; charset=UTF-8' ];
+ $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($ctx->{-res_hdr},
+ $ctx->{env});
bless $ctx, __PACKAGE__;
}
sub async_eml { # for async_blob_cb
my ($ctx, $eml) = @_;
- $ctx->{http_out}->write($ctx->translate($ctx->{cb}->($ctx, $eml)));
+ $ctx->write($ctx->{cb}->($ctx, $eml));
}
sub html_top ($) {
my ($ctx) = @_;
- my $ibx = $ctx->{ibx};
+ my $ibx = $ctx->{ibx} // $ctx->{git};
my $desc = ascii_html($ibx->description);
my $title = delete($ctx->{-title_html}) // $desc;
my $upfx = $ctx->{-upfx} || '';
@@ -49,6 +52,8 @@ sub html_top ($) {
# we had some kind of query, link to /$INBOX/?t=YYYYMMDDhhmmss
} elsif ($ctx->{qp}->{t}) {
$top = qq($top);
+ } elsif (length($upfx)) {
+ $top = qq($top);
}
my $code = $ibx->{coderepo} ? qq( / code) : '';
# id=mirror must exist for legacy bookmarks
@@ -79,38 +84,71 @@ sub html_top ($) {
''. $top . (delete($ctx->{-html_tip}) // '');
}
+sub inboxes { () } # TODO
+
sub coderepos ($) {
my ($ctx) = @_;
+ $ctx->{ibx} // return inboxes($ctx);
my $cr = $ctx->{ibx}->{coderepo} // return ();
- my $cfg = $ctx->{www}->{pi_cfg};
my $upfx = ($ctx->{-upfx} // ''). '../';
- my @ret;
- for my $cr_name (@$cr) {
- $ret[0] //= <code repositories for project(s) associated with this inbox:
-EOF
- my $urls = $cfg->get_all("coderepo.$cr_name.cgiturl");
- if ($urls) {
- for (@$urls) {
- # relative or absolute URL?, prefix relative
- # "foo.git" with appropriate number of "../"
- my $u = m!\A(?:[a-z\+]+:)?//! ? $_ : $upfx.$_;
- $u = ascii_html(prurl($ctx->{env}, $u));
- $ret[0] .= qq(\n\t$u);
- }
- } else {
- $ret[0] .= qq[\n\t$cr_name.git (no URL configured)];
+ my $pfx = $ctx->{base_url} //= $ctx->base_url;
+ my $up = $upfx =~ tr!/!/!;
+ $pfx =~ s!/[^/]+\z!/! for (1..$up);
+ $pfx .= '/' if substr($pfx, -1, 1) ne '/';
+ my $buf = '' .
+ 'Code repositories for project(s) associated with this '.
+ $ctx->{ibx}->thing_type . "\n";
+ for my $git (@{$ctx->{www}->{pi_cfg}->repo_objs($ctx->{ibx})}) {
+ for ($git->pub_urls($ctx->{env})) {
+ my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ : $pfx.$_;
+ $u = ascii_html(prurl($ctx->{env}, $u));
+ $buf .= qq(\n\t$u);
}
}
- @ret; # may be empty, this sub is called as an arg for join()
+ ($buf);
}
sub _html_end {
my ($ctx) = @_;
- my @cr = coderepos($ctx);
- scalar(@cr) ?
- '
'.join("\n\n", @cr).'