X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FFeed.pm;h=c16c417a099e9e6b88bdc94e5f9897e37293380a;hb=2c69f7bc34a2b12dc7f55e2bb24fa28565f24f03;hp=54fa6e5de6d389775d0297873fdda36a1c3aff20;hpb=0b766f54ad829d08cc7bd66fffc8ed8515241dc3;p=public-inbox.git diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index 54fa6e5d..c16c417a 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,33 @@ 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} = ''; + my $res = PublicInbox::WwwStream->new($ctx, 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; + }); + [ 200, ['Content-Type', 'text/html; charset=UTF-8'], $res ] +} + # private subs sub title_tag { @@ -61,32 +88,32 @@ sub atom_header { sub emit_atom { my ($cb, $ctx) = @_; + my $feed_opts = get_feedopts($ctx); my $fh = $cb->([ 200, ['Content-Type' => 'application/atom+xml']]); my $max = $ctx->{max} || MAX_PER_PAGE; - my $feed_opts = get_feedopts($ctx); 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; } @@ -95,35 +122,27 @@ sub emit_atom_thread { my ($cb, $ctx) = @_; my $res = $ctx->{srch}->get_thread($ctx->{mid}); return _no_thread($cb) unless $res->{total}; - my $fh = $cb->([200, ['Content-Type' => 'application/atom+xml']]); my $feed_opts = get_feedopts($ctx); + my $fh = $cb->([200, ['Content-Type' => 'application/atom+xml']]); my $html_url = $feed_opts->{atomurl} = $ctx->{self_url}; $html_url =~ s!/t\.atom\z!/!; $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 $fh = $res->([200,['Content-Type'=>'text/html; charset=UTF-8']]); - - my $max = $ctx->{max} || MAX_PER_PAGE; - my $feed_opts = get_feedopts($ctx); +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{