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
}
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>';
sub feed_entry {
my ($class, $mime, $full_pfx) = @_;
+ # no <head> here for <style>...
PublicInbox::Hval::PRE .
multipart_text_as_html($mime, $full_pfx) . '</pre>';
}
}
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>";
"<a\nhref=\"${path}$href/T/#u\">flat</a>]";
}
}
-
- $fh->write($rv .= '</pre></td></tr></table>');
+ $fh->write($rv .= '</pre>');
}
sub thread_html {
seen => $seen,
root_anchor => anchor_for($mid),
anchor_idx => 0,
+ max_level => 0,
};
require PublicInbox::Git;
} 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;
$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;
}
}
$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 {
$$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>");
}
qq{[parent not found: <<a\nhref="$upfx$href/">$html</a>>]};
}
-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 {
} 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 ];
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);
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";
}
_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";
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";