1 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # HTML body stream for which yields getline+close methods
5 package PublicInbox::WwwStream;
8 use PublicInbox::Hval qw(ascii_html);
10 use constant PI_URL => 'https://public-inbox.org/';
15 my ($class, $ctx, $cb) = @_;
16 bless { nr => 0, cb => $cb || *close, ctx => $ctx }, $class;
20 my ($class, $ctx, $code, $cb) = @_;
21 [ $code, [ 'Content-Type', 'text/html; charset=UTF-8' ],
22 $class->new($ctx, $cb) ]
27 my $ctx = $self->{ctx};
28 my $obj = $ctx->{-inbox};
29 my $desc = ascii_html($obj->description);
30 my $title = $ctx->{-title_html} || $desc;
31 my $upfx = $ctx->{-upfx} || '';
32 my $atom = $ctx->{-atom} || $upfx.'new.atom';
33 my $tip = $ctx->{-html_tip} || '';
34 my $top = "<b>$desc</b> (<a\nhref=\"$atom\">Atom feed</a>)";
36 my $q_val = $ctx->{-q_value_html};
37 if (defined $q_val && $q_val ne '') {
38 $q_val = qq(\nvalue="$q_val" );
42 # XXX gross, for SearchView.pm
43 my $extra = $ctx->{-extra_form_html} || '';
44 my $action = $upfx eq '' ? './' : $upfx;
45 $top = qq{<form\naction="$action"><pre>$top} .
46 qq{ <input\nname=q\ntype=text$q_val/>} .
48 qq{<input\ntype=submit\nvalue=search />} .
51 $top = '<pre>' . $top . '</pre>';
53 "<html><head><title>$title</title>" .
54 "<link\nrel=alternate\ntitle=\"Atom feed\"\n".
55 "href=\"$atom\"\ntype=\"application/atom+xml\"/>" .
56 PublicInbox::Hval::STYLE .
57 "</head><body>". $top . $tip;
62 my $urls = 'Archives are clonable:';
63 my $ctx = $self->{ctx};
64 my $obj = $ctx->{-inbox};
65 my $desc = ascii_html($obj->description);
67 my $http = $obj->base_url($ctx->{env});
69 my %seen = ( $http => 1 );
71 foreach my $u (@{$obj->cloneurl}) {
74 push @urls, $u =~ /\Ahttps?:/ ? qq(<a\nhref="$u">$u</a>) : $u;
76 if (scalar(@urls) == 1) {
77 $urls .= " git clone --mirror $http";
80 join("\n", map { "\tgit clone --mirror $_" } @urls);
82 my $url = PublicInbox::Hval::prurl($ctx->{env}, PI_URL);
86 'Served with public-inbox: '.
87 qq(git clone <a\nhref="$url">$url</a> public-inbox),
88 ).'</pre></body></html>';
93 my $nr = $self->{nr}++;
95 return _html_top($self) if $nr == 0;
97 if (my $mid = $self->{cb}) { # middle
98 $mid = $mid->($nr, $self->{ctx}) and return $mid;
101 delete $self->{cb} ? _html_end($self) : undef;