]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WWW.pm
implement per-thread Atom feeds
[public-inbox.git] / lib / PublicInbox / WWW.pm
index 8058f3e1b1c2f998cadc053891c2f9f5a9c80d6c..c99c25f827cc79db447044c6a5ca639e29add4d9 100644 (file)
@@ -17,12 +17,10 @@ use constant SSOMA_URL => 'http://ssoma.public-inbox.org/';
 use constant PI_URL => 'http://public-inbox.org/';
 our $LISTNAME_RE = qr!\A/([\w\.\-]+)!;
 our $pi_config;
-BEGIN {
-       $pi_config = PublicInbox::Config->new;
-}
 
 sub run {
        my ($cgi, $method) = @_;
+       $pi_config ||= PublicInbox::Config->new;
        my %ctx = (cgi => $cgi, pi_config => $pi_config);
        if ($method !~ /\AGET|HEAD\z/) {
                return r(405, 'Method Not Allowed');
@@ -58,6 +56,9 @@ sub run {
                invalid_list_mid(\%ctx, $1, $2) ||
                        get_thread_mbox(\%ctx, $sfx);
 
+       } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)/atom\z!o) {
+               invalid_list_mid(\%ctx, $1, $2) || get_thread_atom(\%ctx);
+
        # legacy redirects
        } elsif ($path_info =~ m!$LISTNAME_RE/(t|m|f)/(\S+)\.html\z!o) {
                my $pfx = $2;
@@ -249,7 +250,7 @@ sub do_redirect {
 sub ctx_get {
        my ($ctx, $key) = @_;
        my $val = $ctx->{$key};
-       (defined $val && length $val) or die "BUG: bad ctx, $key unusable\n";
+       (defined $val && $val ne '') or die "BUG: bad ctx, $key unusable\n";
        $val;
 }
 
@@ -350,4 +351,14 @@ sub get_thread_mbox {
        PublicInbox::Mbox::thread_mbox($ctx, $srch, $sfx);
 }
 
+
+# /$LISTNAME/t/$MESSAGE_ID/atom                  -> thread as Atom feed
+sub get_thread_atom {
+       my ($ctx) = @_;
+       searcher($ctx) or return need_search($ctx);
+       $ctx->{self_url} = self_url($ctx->{cgi});
+       require PublicInbox::Feed;
+       PublicInbox::Feed::generate_thread_atom($ctx);
+}
+
 1;