unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 1/2] index group state parameters together for generation
@ 2014-09-15  4:23 Eric Wong
  2014-09-15  4:23 ` [PATCH 2/2] index: add prev/next index navigation Eric Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2014-09-15  4:23 UTC (permalink / raw)
  To: meta; +Cc: Eric Wong

This allows us to more-easily group and pass parameters.
---
 lib/PublicInbox/Feed.pm | 15 +++++++--------
 lib/PublicInbox/View.pm |  5 +++--
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 385e573..1fa38bf 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -86,14 +86,14 @@ sub generate_html_index {
 		} @_;
 	});
 
-	my %seen;
 	# except we sort top-level messages reverse chronologically
+	my $state = [ time, {}, $first ];
 	for (sort { (eval { $b->message->header('X-PI-Date') } || 0) <=>
 		    (eval { $a->message->header('X-PI-Date') } || 0)
 		  } $th->rootset) {
-		dump_msg($_, 0, \$html, time, \%seen, $first);
+		dump_msg($_, 0, \$html, $state);
 	}
-
+	$state = undef;
 	Email::Address->purge_cache;
 
 	my $footer = nav_footer($args->{cgi}, $first, $last, $feed_opts);
@@ -287,14 +287,13 @@ sub add_to_feed {
 }
 
 sub dump_msg {
-	my ($self, $level, $html, $now, $seen, $first) = @_;
+	my ($self, $level, $html, $state) = @_;
 	my $mime = $self->message;
 	if ($mime) {
-		$$html .= PublicInbox::View->index_entry($mime, $now, $level,
-		                                         $seen, $first);
+		$$html .= PublicInbox::View->index_entry($mime, $level, $state);
 	}
-	dump_msg($self->child, $level+1, $html, $now, $seen, $first) if $self->child;
-	dump_msg($self->next, $level, $html, $now, $seen, $first) if $self->next;
+	dump_msg($self->child, $level+1, $html, $state) if $self->child;
+	dump_msg($self->next, $level, $html, $state) if $self->next;
 }
 
 sub do_cat_mail {
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index d3849dc..b3797d3 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -43,8 +43,9 @@ sub feed_entry {
 
 # this is already inside a <pre>
 sub index_entry {
-	my ($class, $mime, $now, $level, $seen, $first) = @_;
-	my $rv = "";
+	my ($class, $mime, $level, $state) = @_;
+	my ($now, $seen, $first) = @$state;
+	my $rv = '';
 	my $part_nr = 0;
 	my $enc_msg = enc_for($mime->header("Content-Type"));
 	my $subj = $mime->header('Subject');
-- 
EW


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] index: add prev/next index navigation
  2014-09-15  4:23 [PATCH 1/2] index group state parameters together for generation Eric Wong
@ 2014-09-15  4:23 ` Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2014-09-15  4:23 UTC (permalink / raw)
  To: meta; +Cc: Eric Wong

This helps readers jump around more quickly when there are
large messages.
---
 lib/PublicInbox/Feed.pm | 19 +++++++++++--------
 lib/PublicInbox/View.pm | 10 +++++++++-
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 1fa38bf..791d198 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -87,30 +87,33 @@ sub generate_html_index {
 	});
 
 	# except we sort top-level messages reverse chronologically
-	my $state = [ time, {}, $first ];
+	my $state = [ time, {}, $first, 0 ];
 	for (sort { (eval { $b->message->header('X-PI-Date') } || 0) <=>
 		    (eval { $a->message->header('X-PI-Date') } || 0)
 		  } $th->rootset) {
 		dump_msg($_, 0, \$html, $state);
 	}
-	$state = undef;
 	Email::Address->purge_cache;
 
-	my $footer = nav_footer($args->{cgi}, $first, $last, $feed_opts);
-	my $list_footer = $args->{footer};
-	$footer .= "\n" . $list_footer if ($footer && $list_footer);
-	$footer = "<hr />" . PRE_WRAP . "$footer</pre>" if $footer;
+	my $footer = nav_footer($args->{cgi}, $last, $feed_opts, $state);
+	if ($footer) {
+		my $list_footer = $args->{footer};
+		$footer .= "\n" . $list_footer if $list_footer;
+		$footer = "<hr />" . PRE_WRAP . "$footer</pre>";
+	}
 	$html . "</pre>$footer</html>";
 }
 
 # private subs
 
 sub nav_footer {
-	my ($cgi, $first, $last, $feed_opts) = @_;
+	my ($cgi, $last, $feed_opts, $state) = @_;
 	$cgi or return '';
 	my $old_r = $cgi->param('r');
 	my $head = '    ';
 	my $next = '    ';
+	my $first = $state->[2];
+	my $anchor = $state->[3];
 
 	if ($last) {
 		$next = qq!<a\nhref="?r=$last">next</a>!;
@@ -121,7 +124,7 @@ sub nav_footer {
 	}
 	my $atom = "<a\nhref=\"$feed_opts->{atomurl}\">atom</a>";
 	my $permalink = "<a\nhref=\"?r=$first\">permalink</a>";
-	"$next $head $atom $permalink";
+	"<a\nname=\"s$anchor\">page:</a> $next $head $atom $permalink";
 }
 
 sub each_recent_blob {
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index b3797d3..ce63f7d 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -45,6 +45,8 @@ sub feed_entry {
 sub index_entry {
 	my ($class, $mime, $level, $state) = @_;
 	my ($now, $seen, $first) = @$state;
+	my $midx = $state->[3]++;
+	my ($prev, $next) = ($midx - 1, $midx + 1);
 	my $rv = '';
 	my $part_nr = 0;
 	my $enc_msg = enc_for($mime->header("Content-Type"));
@@ -75,7 +77,13 @@ sub index_entry {
 	}
 	$ts = POSIX::strftime($fmt, gmtime($ts));
 
-	$rv .= "$pfx<a\nname=\"$name\"><b>$subj</b> $from - $ts</a>\n\n";
+	$rv .= "$pfx<a\nname=\"$name\"></a>" .
+		"<a\nname=\"s$midx\"></a>" .
+		"<b>$subj</b> $from - $ts\n" .
+		"$pfx<a\nhref=\"#s$next\">next</a>";
+
+	$rv .= " <a\nhref=\"#s$prev\">prev</a>" if $prev >= 0;
+	$rv .= "\n";
 
 	my $irp = $header_obj->header_raw('In-Reply-To');
 	my ($anchor_idx, $anchor);
-- 
EW


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-09-15  4:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-15  4:23 [PATCH 1/2] index group state parameters together for generation Eric Wong
2014-09-15  4:23 ` [PATCH 2/2] index: add prev/next index navigation Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).