]> Sergey Matveev's repositories - public-inbox.git/commitdiff
feed: add $INBOX/new.html endpoint
authorEric Wong <e@80x24.org>
Thu, 30 Jun 2016 02:35:18 +0000 (02:35 +0000)
committerEric Wong <e@80x24.org>
Thu, 30 Jun 2016 07:24:47 +0000 (07:24 +0000)
This acts like the Atom feed; but should be viewable directly
from browsers.

lib/PublicInbox/Feed.pm
lib/PublicInbox/WWW.pm

index ddc1e3c14f8b3fc4860f73363ac10cf8c6f84efe..c16c417a099e9e6b88bdc94e5f9897e37293380a 100644 (file)
@@ -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} = '<pre>';
+       $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 .= '</pre>' unless $more;
+                       return $s;
+               }
+               undef;
+       });
+       [ 200, ['Content-Type', 'text/html; charset=UTF-8'], $res ]
+}
+
 # private subs
 
 sub title_tag {
index 196486f25e9b0358849d74c4f8df627897d5294a..da5c1d304f89143a2fedc79e1649c4d521f4ad13 100644 (file)
@@ -75,7 +75,8 @@ sub call {
                invalid_inbox($self, $ctx, $1) || get_index($ctx);
        } elsif ($path_info =~ m!$INBOX_RE/(?:atom\.xml|new\.atom)\z!o) {
                invalid_inbox($self, $ctx, $1) || get_atom($ctx);
-
+       } elsif ($path_info =~ m!$INBOX_RE/new\.html\z!o) {
+               invalid_inbox($self, $ctx, $1) || get_new($ctx);
        } elsif ($path_info =~ m!$INBOX_RE/
                                ($PublicInbox::GitHTTPBackend::ANY)\z!ox) {
                my $path = $2;
@@ -189,6 +190,13 @@ sub get_atom {
        PublicInbox::Feed::generate($ctx);
 }
 
+# /$INBOX/new.html                     -> HTML only
+sub get_new {
+       my ($ctx) = @_;
+       require PublicInbox::Feed;
+       PublicInbox::Feed::new_html($ctx);
+}
+
 # /$INBOX/?r=$GIT_COMMIT                 -> HTML only
 sub get_index {
        my ($ctx) = @_;