about summary refs log tree commit homepage
path: root/lib/PublicInbox/Feed.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-04-17 22:23:01 +0000
committerEric Wong <e@80x24.org>2014-04-17 22:23:01 +0000
commit5a90d23bab2c917c08d73d51679c6aae9fb7d526 (patch)
tree322a901fbc67408fe7a50d3b4bae04eb12063085 /lib/PublicInbox/Feed.pm
parent07d0e0cbd7ba54fe40d12d168fdb95efc3c3ad0c (diff)
downloadpublic-inbox-5a90d23bab2c917c08d73d51679c6aae9fb7d526.tar.gz
This is hopefully the most user-friendly method.
Diffstat (limited to 'lib/PublicInbox/Feed.pm')
-rw-r--r--lib/PublicInbox/Feed.pm14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 33406522..9db4e17d 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -11,7 +11,7 @@ use Encode qw/find_encoding/;
 use Encode::MIME::Header;
 use CGI qw(escapeHTML);
 use POSIX qw(strftime);
-use Date::Parse qw(strptime);
+use Date::Parse qw(strptime str2time);
 use constant DATEFMT => '%Y-%m-%dT%H:%M:%SZ';
 use PublicInbox::View;
 use Mail::Thread;
@@ -66,6 +66,10 @@ sub generate_html_index {
                         return 0;
                 }
                 $simple->body_set(""); # save some memory
+
+                my $t = eval { str2time($simple->header('Date')) };
+                defined($t) or $t = 0;
+                $simple->header_set('X-PI-Date', $t);
                 push @messages, $simple;
                 1;
         });
@@ -78,6 +82,14 @@ sub generate_html_index {
                 $feed_opts->{atomurl} . '" type="application/atom+xml"/>' .
                 '</head><body><pre>');
         push @args, $feed_opts->{midurl};
+
+        # sort by date, most recent at top
+        $th->order(sub {
+                sort {
+                        $b->topmost->message->header('X-PI-Date') <=>
+                        $a->topmost->message->header('X-PI-Date')
+                } @_;
+        });
         dump_html_line($_, 0, \@args) for $th->rootset;
         $args[0] . '</pre></html>';
 }