]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WwwListing.pm
www: improve navigation around contemporary threads
[public-inbox.git] / lib / PublicInbox / WwwListing.pm
index 38a37ddaae977f129081f4b054f4ac9a1076385b..365743cfdf90d13bc4b56b95297dc1d04e93f716 100644 (file)
@@ -6,10 +6,11 @@
 package PublicInbox::WwwListing;
 use strict;
 use warnings;
-use PublicInbox::Hval qw(ascii_html prurl);
+use PublicInbox::Hval qw(ascii_html prurl fmt_ts);
 use PublicInbox::Linkify;
 use PublicInbox::View;
 use PublicInbox::Inbox;
+use PublicInbox::GzipFilter qw(gzf_maybe);
 use bytes (); # bytes::length
 use HTTP::Date qw(time2str);
 use Digest::SHA ();
@@ -39,7 +40,7 @@ sub list_all ($$$) {
 sub list_match_domain_i {
        my ($ibx, $arg) = @_;
        my ($list, $hide_key, $re) = @$arg;
-       if (!$ibx->{-hide}->{$hide_key} && grep($re, @{$ibx->{url}})) {
+       if (!$ibx->{-hide}->{$hide_key} && grep(/$re/, @{$ibx->{url}})) {
                push @$list, $ibx;
        }
 }
@@ -90,7 +91,7 @@ sub new {
 
 sub ibx_entry {
        my ($mtime, $ibx, $env) = @_;
-       my $ts = PublicInbox::View::fmt_ts($mtime);
+       my $ts = fmt_ts($mtime);
        my $url = prurl($env, $ibx->{url});
        my $tmp = <<"";
 * $ts - $url
@@ -104,13 +105,15 @@ sub ibx_entry {
 
 sub html ($$) {
        my ($env, $list) = @_;
-       my $title = 'public-inbox';
-       my $out = '';
+       my $h = [ 'Content-Type', 'text/html; charset=UTF-8',
+                       'Content-Length', undef ];
+       my $gzf = gzf_maybe($h, $env);
+       $gzf->zmore('<html><head><title>' .
+                               'public-inbox listing</title>' .
+                               '</head><body><pre>');
        my $code = 404;
        if (@$list) {
-               $title .= ' - listing';
                $code = 200;
-
                # Schwartzian transform since Inbox->modified is expensive
                @$list = sort {
                        $b->[0] <=> $a->[0]
@@ -118,13 +121,14 @@ sub html ($$) {
 
                my $tmp = join("\n", map { ibx_entry(@$_, $env) } @$list);
                my $l = PublicInbox::Linkify->new;
-               $out = '<pre>'.$l->to_html($tmp).'</pre><hr>';
+               $gzf->zmore($l->to_html($tmp));
+       } else {
+               $gzf->zmore('no inboxes, yet');
        }
-       $out = "<html><head><title>$title</title></head><body>" . $out;
-       $out .= '<pre>'. PublicInbox::WwwStream::code_footer($env) .
-               '</pre></body></html>';
-
-       my $h = [ 'Content-Type', 'text/html; charset=UTF-8' ];
+       my $out = $gzf->zflush('</pre><hr><pre>'.
+                               PublicInbox::WwwStream::code_footer($env) .
+                               '</pre></body></html>');
+       $h->[3] = bytes::length($out);
        [ $code, $h, [ $out ] ];
 }
 
@@ -157,6 +161,8 @@ sub manifest_add ($$;$$) {
 
        chomp(my $owner = $git->qx('config', 'gitweb.owner'));
        chomp(my $desc = try_cat("$git_dir/description"));
+       utf8::decode($owner);
+       utf8::decode($desc);
        $owner = undef if $owner eq '';
        $desc = 'Unnamed repository' if $desc eq '';