X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FFeed.pm;h=ffbf5c8062bb2121e2a0eeaca1dd517d7c8d01e6;hb=e358bd7a3833f8c5bf9db57d228888f9c5f3692e;hp=52fe0db4ac9ece1d5431a363b1646c1150e12449;hpb=19e00ca1a6aab8e59f74241fcdfbb768785ff2ff;p=public-inbox.git diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index 52fe0db4..ffbf5c80 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -5,13 +5,13 @@ package PublicInbox::Feed; use strict; use warnings; -use Email::Address; use Email::MIME; use Date::Parse qw(strptime); use PublicInbox::Hval qw/ascii_html/; use PublicInbox::Git; use PublicInbox::View; use PublicInbox::MID qw/mid_clean mid2path/; +use PublicInbox::Address; use POSIX qw/strftime/; use constant { DATEFMT => '%Y-%m-%dT%H:%M:%SZ', # Atom standard @@ -34,6 +34,32 @@ sub generate_html_index { sub { emit_html_index($_[0], $ctx) }; } +sub new_html { + my ($ctx) = @_; + my @paths; + my (undef, $last) = each_recent_blob($ctx, sub { + my ($path, $commit, $ts, $u, $subj) = @_; + $ctx->{first} ||= $commit; + push @paths, $path; + }); + if (!@paths) { + return [404, ['Content-Type', 'text/plain'], + ["No messages, yet\n"] ]; + } + $ctx->{-html_tip} = '
'; + $ctx->{-upfx} = ''; + PublicInbox::WwwStream->response($ctx, 200, sub { + while (my $path = shift @paths) { + my $m = do_cat_mail($ctx->{-inbox}, $path) or next; + my $more = scalar @paths; + my $s = PublicInbox::View::index_entry($m, $ctx, $more); + $s .= '' unless $more; + return $s; + } + undef; + }); +} + # private subs sub title_tag { @@ -65,28 +91,28 @@ sub emit_atom { my $fh = $cb->([ 200, ['Content-Type' => 'application/atom+xml']]); my $max = $ctx->{max} || MAX_PER_PAGE; my $x = atom_header($feed_opts); - my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir}); + my $ibx = $ctx->{-inbox}; each_recent_blob($ctx, sub { my ($path, undef, $ts) = @_; if (defined $x) { $fh->write($x . feed_updated(undef, $ts)); $x = undef; } - add_to_feed($feed_opts, $fh, $path, $git); + my $s = feed_entry($feed_opts, $path, $ibx) or return 0; + $fh->write($s); + 1; }); end_feed($fh); } sub _no_thread { my ($cb) = @_; - my $fh = $cb->([404, ['Content-Type' => 'text/plain']]); - $fh->write("No feed found for thread\n"); - $fh->close; + $cb->([404, ['Content-Type', 'text/plain'], + ["No feed found for thread\n"]]); } sub end_feed { my ($fh) = @_; - Email::Address->purge_cache; $fh->write(''); $fh->close; } @@ -103,27 +129,19 @@ sub emit_atom_thread { $feed_opts->{url} = $html_url; $feed_opts->{emit_header} = 1; - my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir}); + my $ibx = $ctx->{-inbox}; foreach my $msg (@{$res->{msgs}}) { - add_to_feed($feed_opts, $fh, mid2path($msg->mid), $git); + my $s = feed_entry($feed_opts, mid2path($msg->mid), $ibx); + $fh->write($s) if defined $s; } end_feed($fh); } -sub emit_html_index { - my ($res, $ctx) = @_; - my $feed_opts = get_feedopts($ctx); - my $fh = $res->([200,['Content-Type'=>'text/html; charset=UTF-8']]); - - my $max = $ctx->{max} || MAX_PER_PAGE; +sub _html_index_top { + my ($feed_opts, $srch) = @_; my $title = ascii_html($feed_opts->{description} || ''); - my ($footer, $param, $last); - my $state = { ctx => $ctx, seen => {}, anchor_idx => 0, fh => $fh }; - my $srch = $ctx->{srch}; - my $top = "$title (Atom feed)"; - if ($srch) { $top = qq{