]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
view: thread using <ul> instead of <table>
[public-inbox.git] / lib / PublicInbox / View.pm
index 98d0219dbc57c353163872c9269e63da16d67641..bcd2ebc4cc8d0fd0df24e99a6c922d06de835536 100644 (file)
@@ -15,7 +15,6 @@ use PublicInbox::Hval;
 use PublicInbox::MID qw/mid_clean id_compress mid2path/;
 use Digest::SHA qw/sha1_hex/;
 my $SALT = rand;
-my $MBOX_TITLE = 'title="download thread as gzipped mbox"';
 require POSIX;
 
 # TODO: make these constants tunable
@@ -38,7 +37,7 @@ sub msg_html {
        }
        headers_to_html_header($mime, $full_pfx, $ctx) .
                multipart_text_as_html($mime, $full_pfx) .
-               '</pre><hr />' . PublicInbox::Hval::PRE .
+               '</pre><hr /><pre>' .
                html_footer($mime, 1, $full_pfx, $ctx) .
                $footer .
                '</pre></body></html>';
@@ -47,6 +46,7 @@ sub msg_html {
 sub feed_entry {
        my ($class, $mime, $full_pfx) = @_;
 
+       # no <head> here for <style>...
        PublicInbox::Hval::PRE .
                multipart_text_as_html($mime, $full_pfx) . '</pre>';
 }
@@ -103,11 +103,7 @@ sub index_entry {
        }
 
        my $ts = _msg_date($mime);
-       my $rv = "<table\nsummary=l$level><tr>";
-       if ($level) {
-               $rv .= '<td><pre>' . (INDENT x $level) . '</pre></td>';
-       }
-       $rv .= "<td\nid=s$midx>" . PublicInbox::Hval::PRE;
+       my $rv = "<pre\nid=s$midx>";
        $rv .= "<b\nid=$id>$subj</b>\n";
        $rv .= "- $from @ $ts UTC - ";
        $rv .= "<a\nhref=\"#s$next\">next</a>";
@@ -155,8 +151,7 @@ sub index_entry {
                                "<a\nhref=\"${path}$href/T/#u\">flat</a>]";
                }
        }
-
-       $fh->write($rv .= '</pre></td></tr></table>');
+       $fh->write($rv .= '</pre>');
 }
 
 sub thread_html {
@@ -181,6 +176,7 @@ sub emit_thread_html {
                seen => $seen,
                root_anchor => anchor_for($mid),
                anchor_idx => 0,
+               max_level => 0,
        };
 
        require PublicInbox::Git;
@@ -191,6 +187,10 @@ sub emit_thread_html {
        } else {
                my $th = thread_results($msgs);
                thread_entry(\$cb, $git, $state, $_, 0) for $th->rootset;
+               if (my $max = $state->{max_level}) {
+                       my $x = $max > 1 ? ('</ul></li>' x ($max-1)) : '';
+                       $cb->write($x . '</ul>');
+               }
        }
        $git = undef;
        Email::Address->purge_cache;
@@ -204,10 +204,10 @@ sub emit_thread_html {
        $next .= $final_anchor == 1 ? 'only message in' : 'end of';
        $next .= " thread</a>, back to <a\nhref=\"../../\">index</a>";
        $next .= "\ndownload thread: ";
-       $next .= "<a\n$MBOX_TITLE\nhref=\"../t.mbox.gz\">mbox.gz</a>";
+       $next .= "<a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
        $next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>";
-       $cb->write("<hr />" . PublicInbox::Hval::PRE . $next . "\n\n".
-               $foot .  "</pre></body></html>");
+       $cb->write('<hr /><pre>' . $next . "\n\n".
+                       $foot .  '</pre></body></html>');
        $cb->close;
 }
 
@@ -451,8 +451,8 @@ sub headers_to_html_header {
        }
        $rv .= "\n";
 
-       ("<html><head><title>".  join(' - ', @title) .
-        "</title>$atom</head><body>" . PublicInbox::Hval::PRE . $rv);
+       ("<html><head><title>".  join(' - ', @title) . "</title>$atom".
+        PublicInbox::Hval::STYLE . "</head><body><pre>" . $rv);
 }
 
 sub thread_inline {
@@ -616,6 +616,7 @@ sub thread_html_head {
        $$cb->write("<html><head><title>$s</title>".
                qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
                qq!href="../t.atom"\ntype="application/atom+xml"/>! .
+               PublicInbox::Hval::STYLE .
                "</head><body>");
 }
 
@@ -636,12 +637,25 @@ sub ghost_parent {
        qq{[parent not found: &lt;<a\nhref="$upfx$href/">$html</a>&gt;]};
 }
 
-sub ghost_table {
-       my ($upfx, $mid, $level) = @_;
-       "<table\nsummary=ghost><tr><td>" .
-               (INDENT x $level) . "</td><td>" .
-               PublicInbox::Hval::PRE . ghost_parent($upfx, $mid) .
-               '</pre></td></table>';
+sub __thread_adj_level {
+       my ($cb, $state, $level) = @_;
+
+       return if $level <= 0; # flat output
+       my $max = $state->{max_level};
+       if ($level > $max) {
+               $state->{max_level} = $level;
+               $$cb->write(($max ? '<li>' : ''). '<ul><li>');
+       } else {
+               $$cb->write('<li>');
+       }
+}
+
+sub __ghost_flush {
+       my ($cb, $state, $upfx, $mid, $level) = @_;
+
+       __thread_adj_level($cb, $state, $level);
+       $$cb->write('<pre>'. ghost_parent($upfx, $mid) .  '</pre>' .
+                       ($level > 0 ? '</li>' : ''));
 }
 
 sub __thread_entry {
@@ -654,20 +668,23 @@ sub __thread_entry {
        } or return;
 
        if ($state->{anchor_idx} == 0) {
-               thread_html_head($cb, $mime, $state);
+               thread_html_head($cb, $mime, $state, $level);
        }
 
        if (my $ghost = delete $state->{ghost}) {
                # n.b. ghost messages may only be parents, not children
                foreach my $g (@$ghost) {
-                       $$cb->write(ghost_table('../../', @$g));
+                       __ghost_flush($cb, $state, '../../', @$g);
                }
        }
+       __thread_adj_level($cb, $state, $level);
        index_entry($$cb, $mime, $level, $state);
+       $$cb->write('</li>') if $level > 0;
+
        1;
 }
 
-sub __ghost_entry {
+sub __ghost_prepare {
        my ($state, $node, $level) = @_;
        my $ghost = $state->{ghost} ||= [];
        push @$ghost, [ $node->messageid, $level ];
@@ -678,10 +695,10 @@ sub thread_entry {
        return unless $node;
        if (my $mime = $node->message) {
                unless (__thread_entry($cb, $git, $state, $mime, $level)) {
-                       __ghost_entry($state, $node, $level);
+                       __ghost_prepare($state, $node, $level);
                }
        } else {
-               __ghost_entry($state, $node, $level);
+               __ghost_prepare($state, $node, $level);
        }
 
        thread_entry($cb, $git, $state, $node->child, $level + 1);
@@ -774,7 +791,7 @@ sub _inline_header {
        my $m = PublicInbox::Hval->new_msgid($mid);
        $m = $upfx . '../' . $m->as_href . '/';
        if (defined $s) {
-               $$dst .= "$pfx$dot<a\nhref=\"$m\">$s</a>$attr\n";
+               $$dst .= "$pfx$dot<a\nhref=\"$m\">$s</a> $attr\n";
        } else {
                $$dst .= "$pfx$dot<a\nhref=\"$m\">$f</a>\n";
        }
@@ -791,7 +808,7 @@ sub inline_dump {
                _inline_header($dst, $state, $upfx, $mime, $level);
        } else {
                my $dot = $level == 0 ? '' : '` ';
-               my $pfx = length(' 1970-01-01 13:37 ') .
+               my $pfx = (' ' x length(' 1970-01-01 13:37 ')).
                        (INDENT x $level) . $dot;
                $$dst .= $pfx;
                $$dst .= ghost_parent("$upfx../", $node->messageid) . "\n";
@@ -877,19 +894,15 @@ sub dump_topics {
 
                my $attr;
                $ts = fmt_ts($ts);
-               if ($n == 1) {
-                       $attr = "@ $ts UTC";
-                       $n = "";
-               } else {
-                       # $n isn't the total number of posts on the topic,
-                       # just the number of posts in the current results
-                       # window, so leave it unlabeled
-                       $attr = "@ $ts UTC";
-                       $n = " ($n)";
-               }
+               $attr = " $ts UTC";
+
+               # $n isn't the total number of posts on the topic,
+               # just the number of posts in the current results
+               # window, so leave it unlabeled
+               $n = $n == 1 ? '' : " ($n+ messages)";
+
                if ($level == 0 || $attr ne $prev_attr) {
-                       my $mbox = qq(<a\n$MBOX_TITLE\n) .
-                                  qq(href="$mid/t.mbox.gz">mbox.gz</a>);
+                       my $mbox = qq(<a\nhref="$mid/t.mbox.gz">mbox.gz</a>);
                        my $atom = qq(<a\nhref="$mid/t.atom">Atom</a>);
                        $pfx .= INDENT if $level > 0;
                        $dst .= $pfx . $attr . $n . " - $mbox / $atom\n";