user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 1/3] feed: consolidate updated tag generation
@ 2015-09-13 22:35 Eric Wong
  2015-09-13 22:35 ` [PATCH 2/3] searchview: implement Atom feed for search results Eric Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Eric Wong @ 2015-09-13 22:35 UTC (permalink / raw)
  To: meta

We'll be reusing this code further in the next commit.
---
 lib/PublicInbox/Feed.pm | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 258ef03..5a2f62b 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -68,9 +68,7 @@ sub emit_atom {
 	each_recent_blob($ctx, sub {
 		my ($path, undef, $ts) = @_;
 		if (defined $x) {
-			$fh->write($x . '<updated>' .
-				   strftime(DATEFMT, gmtime($ts)) .
-				   '</updated>');
+			$fh->write($x . feed_updated(undef, $ts));
 			$x = undef;
 		}
 		add_to_feed($feed_opts, $fh, $path, $git);
@@ -317,11 +315,12 @@ sub mime_header {
 	PublicInbox::Hval->new_oneline($mime->header($name))->raw;
 }
 
-sub feed_date {
-	my ($date) = @_;
-	my @t = eval { strptime($date) };
+sub feed_updated {
+	my ($date, $ts) = @_;
+	my @t = eval { strptime($date) } if defined $date;
+	@t = gmtime($ts || time) unless scalar @t;
 
-	scalar(@t) ? strftime(DATEFMT, @t) : 0;
+	'<updated>' . strftime(DATEFMT, @t) . '</updated>';
 }
 
 # returns 0 (skipped) or 1 (added)
@@ -342,9 +341,7 @@ sub add_to_feed {
 	$mime = undef;
 
 	my $date = $header_obj->header('Date');
-	$date = PublicInbox::Hval->new_oneline($date);
-	$date = feed_date($date->raw) or return 0;
-	$date = "<updated>$date</updated>";
+	my $updated = feed_updated($date);
 
 	my $title = mime_header($header_obj, 'Subject') or return 0;
 	$title = title_tag($title);
@@ -356,10 +353,10 @@ sub add_to_feed {
 	$email = PublicInbox::Hval->new_oneline($email)->as_html;
 
 	if (delete $feed_opts->{emit_header}) {
-		$fh->write(atom_header($feed_opts, $title) . $date);
+		$fh->write(atom_header($feed_opts, $title) . $updated);
 	}
 	$fh->write("<entry><author><name>$name</name><email>$email</email>" .
-		   "</author>$title$date" .
+		   "</author>$title$updated" .
 		   qq{<content\ntype="xhtml">} .
 		   qq{<div\nxmlns="http://www.w3.org/1999/xhtml">});
 	$fh->write($content);
-- 
EW


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

* [PATCH 2/3] searchview: implement Atom feed for search results
  2015-09-13 22:35 [PATCH 1/3] feed: consolidate updated tag generation Eric Wong
@ 2015-09-13 22:35 ` Eric Wong
  2015-09-13 22:35 ` [PATCH 3/3] view: add Atom links in headers for per-message links Eric Wong
  2015-09-13 22:37 ` [PATCH 0/3] expand Atom feeds to search results Eric Wong
  2 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2015-09-13 22:35 UTC (permalink / raw)
  To: meta

This can be helpful for folks who want to subscribe
to a particular topic or keyword.
---
 lib/PublicInbox/Feed.pm       |  6 +++---
 lib/PublicInbox/SearchView.pm | 42 +++++++++++++++++++++++++++++++++---------
 2 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 5a2f62b..85c598e 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -74,7 +74,7 @@ sub emit_atom {
 		add_to_feed($feed_opts, $fh, $path, $git);
 	});
 	$git = undef; # destroy pipes
-	_end_feed($fh);
+	end_feed($fh);
 }
 
 sub _no_thread {
@@ -84,7 +84,7 @@ sub _no_thread {
 	$fh->close;
 }
 
-sub _end_feed {
+sub end_feed {
 	my ($fh) = @_;
 	Email::Address->purge_cache;
 	$fh->write('</feed>');
@@ -108,7 +108,7 @@ sub emit_atom_thread {
 		add_to_feed($feed_opts, $fh, mid2path($msg->mid), $git);
 	}
 	$git = undef; # destroy pipes
-	_end_feed($fh);
+	end_feed($fh);
 }
 
 sub emit_html_index {
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index c15a046..b65351a 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -30,7 +30,7 @@ sub sres_top_html {
 		$total = $mset->get_matches_estimated;
 	};
 	my $err = $@;
-	my $res = html_start($q) . PublicInbox::View::PRE_WRAP;
+	my $res = html_start($q, $ctx) . PublicInbox::View::PRE_WRAP;
 	if ($err) {
 		$code = 400;
 		$res .= err_txt($err) . "</pre><hr /><pre>" . foot($ctx);
@@ -39,8 +39,7 @@ sub sres_top_html {
 		$res .= "\n\n[No results found]</pre><hr /><pre>".foot($ctx);
 	} else {
 		my $x = $q->{x};
-		# TODO
-		#return sub { adump($_[0], $mset, $q, $ctx) } if ($x eq 'A');
+		return sub { adump($_[0], $mset, $q, $ctx) } if ($x eq 'A');
 
 		$res .= search_nav_top($mset, $q);
 		if ($x eq 't') {
@@ -109,8 +108,8 @@ sub search_nav_top {
 		$rv .= qq{<a\nhref="?$s">summary</a>|};
 		$rv .= qq{<b>threaded</b>};
 	}
-	# my $A = $q->qs_html(x => 'a');
-	# $rv .= qq{|<a\nhref="?$A">Atom</a>}; # TODO
+	my $A = $q->qs_html(x => 'A');
+	$rv .= qq{|<a\nhref="?$A">Atom</a>};
 	$rv .= ']';
 }
 
@@ -213,13 +212,16 @@ sub foot {
 }
 
 sub html_start {
-	my ($q) = @_;
+	my ($q, $ctx) = @_;
 	my $query = PublicInbox::Hval->new_oneline($q->{q});
 
 	my $qh = $query->as_html;
-	my $res = "<html><head><title>$qh - search results</title></head>" .
-		  qq{<body><form\naction="">} .
-		  qq{<input\nname=q\nvalue="$qh"\ntype=text />};
+	my $A = $q->qs_html(x => 'A');
+	my $res = "<html><head><title>$qh - search results</title>" .
+		qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
+		qq!href="?$A"\ntype="application/atom+xml"/></head>! .
+		qq{<body><form\naction="">} .
+		qq{<input\nname=q\nvalue="$qh"\ntype=text />};
 
 	$res .= qq{<input\ntype=hidden\nname=r />} if $q->{r};
 	if (my $x = $q->{x}) {
@@ -230,6 +232,28 @@ sub html_start {
 	$res .= qq{<input\ntype=submit\nvalue=search /></form>};
 }
 
+sub adump {
+	my ($cb, $mset, $q, $ctx) = @_;
+	my $fh = $cb->([ 200, ['Content-Type' => 'application/atom+xml']]);
+	require PublicInbox::GitCatFile;
+	my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+	my $feed_opts = PublicInbox::Feed::get_feedopts($ctx);
+	my $x = PublicInbox::Hval->new_oneline($q->{q})->as_html;
+	$x = qq{$x - search results};
+	$feed_opts->{atomurl} = $feed_opts->{url} . '?'. $q->qs_html;
+	$feed_opts->{url} .= '?'. $q->qs_html(x => undef);
+	$x = PublicInbox::Feed::atom_header($feed_opts, $x);
+	$fh->write($x. PublicInbox::Feed::feed_updated());
+
+	for ($mset->items) {
+		$x = PublicInbox::SearchMsg->load_doc($_->get_document)->mid;
+		$x = mid2path($x);
+		PublicInbox::Feed::add_to_feed($feed_opts, $fh, $x, $git);
+	}
+	$git = undef;
+	PublicInbox::Feed::end_feed($fh);
+}
+
 package PublicInbox::SearchQuery;
 use strict;
 use warnings;
-- 
EW


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

* [PATCH 3/3] view: add Atom links in headers for per-message links
  2015-09-13 22:35 [PATCH 1/3] feed: consolidate updated tag generation Eric Wong
  2015-09-13 22:35 ` [PATCH 2/3] searchview: implement Atom feed for search results Eric Wong
@ 2015-09-13 22:35 ` Eric Wong
  2015-09-13 22:37 ` [PATCH 0/3] expand Atom feeds to search results Eric Wong
  2 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2015-09-13 22:35 UTC (permalink / raw)
  To: meta

Some user agents will advertise the presence of a feed this
way for users to subscribe to individual topics.
---
 lib/PublicInbox/View.pm | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index de2d667..7e1fb04 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -432,15 +432,19 @@ sub headers_to_html_header {
 	$rv .= 'Message-ID: &lt;' . $mid->as_html . '&gt; ';
 	my $upfx = $full_pfx ? '' : '../';
 	$rv .= "(<a\nhref=\"${upfx}raw\">raw</a>)\n";
+	my $atom;
 	if ($srch) {
 		$rv .= "<a\nhref=\"${upfx}t/\">References: [expand]</a>\n";
+		$atom = qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
+			qq!href="${upfx}t.atom"\ntype="application/atom+xml"/>!;
 	} else {
 		$rv .= _parent_headers_nosrch($header_obj);
+		$atom = '';
 	}
 	$rv .= "\n";
 
 	("<html><head><title>".  join(' - ', @title) .
-	 '</title></head><body>' . PRE_WRAP . $rv);
+	 "</title>$atom</head><body>" . PRE_WRAP . $rv);
 }
 
 sub thread_inline {
@@ -578,12 +582,15 @@ sub anchor_for {
 }
 
 sub thread_html_head {
-	my ($cb, $mime) = @_;
+	my ($cb, $header, $state) = @_;
 	$$cb = $$cb->([200, ['Content-Type'=> 'text/html; charset=UTF-8']]);
 
-	my $s = PublicInbox::Hval->new_oneline($mime->header('Subject'));
+	my $s = PublicInbox::Hval->new_oneline($header->header('Subject'));
 	$s = $s->as_html;
-	$$cb->write("<html><head><title>$s</title></head><body>");
+	$$cb->write("<html><head><title>$s</title>".
+		qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
+		qq!href="../t.atom"\ntype="application/atom+xml"/>! .
+		"</head><body>");
 }
 
 sub pre_anchor_entry {
-- 
EW


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

* [PATCH 0/3] expand Atom feeds to search results
  2015-09-13 22:35 [PATCH 1/3] feed: consolidate updated tag generation Eric Wong
  2015-09-13 22:35 ` [PATCH 2/3] searchview: implement Atom feed for search results Eric Wong
  2015-09-13 22:35 ` [PATCH 3/3] view: add Atom links in headers for per-message links Eric Wong
@ 2015-09-13 22:37 ` Eric Wong
  2015-09-13 23:19   ` [REJECT 4/3] searchview: implement flat view for full message Eric Wong
  2 siblings, 1 reply; 5+ messages in thread
From: Eric Wong @ 2015-09-13 22:37 UTC (permalink / raw)
  To: meta

Oops, forgot cover letter.  Atom feeds for search views are finally
implemented, and Atom links show up in per-message pages, now.

 lib/PublicInbox/Feed.pm       | 27 ++++++++++++---------------
 lib/PublicInbox/SearchView.pm | 42 +++++++++++++++++++++++++++++++++---------
 lib/PublicInbox/View.pm       | 15 +++++++++++----
 3 files changed, 56 insertions(+), 28 deletions(-)

Eric Wong (3):
      feed: consolidate updated tag generation
      searchview: implement Atom feed for search results
      view: add Atom links in headers for per-message links


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

* [REJECT 4/3] searchview: implement flat view for full message
  2015-09-13 22:37 ` [PATCH 0/3] expand Atom feeds to search results Eric Wong
@ 2015-09-13 23:19   ` Eric Wong
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2015-09-13 23:19 UTC (permalink / raw)
  To: meta

Rejecting this, as it's too much clutter and options.
People who really want a flat view should use the Atom feed.
---
 lib/PublicInbox/SearchView.pm | 109 ++++++++++++++++++++++++++++--------------
 1 file changed, 72 insertions(+), 37 deletions(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index b65351a..f0c6670 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -44,7 +44,10 @@ sub sres_top_html {
 		$res .= search_nav_top($mset, $q);
 		if ($x eq 't') {
 			return sub { tdump($_[0], $res, $mset, $q, $ctx) };
+		} elsif ($x eq 'f') {
+			return sub { fdump($_[0], $res, $mset, $q, $ctx) };
 		}
+
 		$res .= "\n\n";
 		dump_mset(\$res, $mset);
 		$res .= search_nav_bot($mset, $q) . "\n\n" . foot($ctx);
@@ -96,17 +99,24 @@ sub search_nav_top {
 		$rv .= qq{<b>date</b>|<a\nhref="?$d">relevance</a>};
 	}
 
-	$rv .= ']  view[';
+	$rv .= ']  view: [';
 
 	my $x = $q->{x};
+	my $t = $q->qs_html(x => 't');
+	my $s = $q->qs_html(x => '');
+	my $f = $q->qs_html(x => 'f');
 	if ($x eq '') {
-		my $t = $q->qs_html(x => 't');
-		$rv .= qq{<b>summary</b>|};
-		$rv .= qq{<a\nhref="?$t">threaded</a>}
-	} elsif ($q->{x} eq 't') {
-		my $s = $q->qs_html(x => '');
-		$rv .= qq{<a\nhref="?$s">summary</a>|};
-		$rv .= qq{<b>threaded</b>};
+		$rv .= qq{<b>short</b>|} .
+			qq{<a\nhref="?$t">threaded</a>|} .
+			qq{<a\nhref="?$f">flat</a>};
+	} elsif ($x eq 't') {
+		$rv .= qq{<a\nhref="?$s">short</a>|} .
+			qq{<b>threaded</b>|} .
+			qq{<a\nhref="?$f">flat</a>};
+	} elsif ($x eq 'f') {
+		$rv .= qq{<a\nhref="?$s">short</a>|} .
+			qq{<a\nhref="?$t">threaded</a>|} .
+			qq{<b>flat</b>};
 	}
 	my $A = $q->qs_html(x => 'A');
 	$rv .= qq{|<a\nhref="?$A">Atom</a>};
@@ -136,8 +146,8 @@ sub search_nav_bot {
 	$rv;
 }
 
-sub tdump {
-	my ($cb, $res, $mset, $q, $ctx) = @_;
+sub dump_prepare {
+	my ($cb, $res, $mset, $ctx) = @_;
 	my $fh = $cb->([200, ['Content-Type'=>'text/html; charset=UTF-8']]);
 	$fh->write($res);
 	my %pct;
@@ -148,56 +158,81 @@ sub tdump {
 		$m = $m->mini_mime;
 		$m;
 	} ($mset->items);
+	my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct };
+	$ctx->{searchview} = 1;
+	require PublicInbox::GitCatFile;
+	my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+	$state->{git} = $git;
+
+	($fh, \@m, $git, $state);
+}
+
+sub dump_end {
+	my ($fh, $mset, $q, $ctx) = @_;
+	Email::Address->purge_cache;
+
+	$fh->write(search_nav_bot($mset, $q). "\n\n" .
+			foot($ctx). '</pre></body></html>');
+	$fh->close;
+}
+
+sub fdump {
+	my ($cb, $res, $mset, $q, $ctx) = @_;
+	my ($fh, $m, $git, $state) = dump_prepare($cb, $res, $mset, $ctx);
+	mime_dump($fh, $git, $_, 0, $state) for (@$m);
+	dump_end($fh, $mset, $q, $ctx);
+}
+
+sub do_thread {
+	my ($m, $pct, $q) = @_;
 
 	require PublicInbox::Thread;
-	my $th = PublicInbox::Thread->new(@m);
+	my $th = PublicInbox::Thread->new(@$m);
 	{
 		no warnings 'once';
 		$Mail::Thread::nosubject = 0;
+		$th->thread;
 	}
-	$th->thread;
 	if ($q->{r}) {
 		$th->order(sub {
-			sort { (eval { $pct{$b->topmost->messageid} } || 0)
+			sort { (eval { $pct->{$b->topmost->messageid} } || 0)
 					<=>
-				(eval { $pct{$a->topmost->messageid} } || 0)
+				(eval { $pct->{$a->topmost->messageid} } || 0)
 			} @_;
 		});
 	} else {
 		no warnings 'once';
 		$th->order(*PublicInbox::View::rsort_ts);
 	}
+	$th;
+}
 
-	require PublicInbox::GitCatFile;
-	my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
-	my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct };
-	$ctx->{searchview} = 1;
+sub tdump {
+	my ($cb, $res, $mset, $q, $ctx) = @_;
+	my ($fh, $m, $git, $state) = dump_prepare($cb, $res, $mset, $ctx);
+	my $th = do_thread($m, $state->{pct}, $q);
 	tdump_ent($fh, $git, $state, $_, 0) for $th->rootset;
-	$git = undef;
-	Email::Address->purge_cache;
+	dump_end($fh, $mset, $q, $ctx);
+}
 
-	$fh->write(search_nav_bot($mset, $q). "\n\n" .
-			foot($ctx). '</pre></body></html>');
+sub mime_dump {
+	my ($fh, $git, $mime, $level, $state) = @_;
 
-	$fh->close;
+	# lazy load the full message from mini_mime:
+	my $mid = $mime->header('Message-ID');
+	$mime = eval {
+		my $path = mid2path(mid_clean($mid));
+		Email::MIME->new($git->cat_file('HEAD:'.$path));
+	};
+	PublicInbox::View::index_entry($fh, $mime, $level, $state) if $mime;
+	$mime;
 }
 
 sub tdump_ent {
 	my ($fh, $git, $state, $node, $level) = @_;
 	return unless $node;
-	my $mime = $node->message;
-
-	if ($mime) {
-		# lazy load the full message from mini_mime:
-		my $mid = $mime->header('Message-ID');
-		$mime = eval {
-			my $path = mid2path(mid_clean($mid));
-			Email::MIME->new($git->cat_file('HEAD:'.$path));
-		};
-	}
-	if ($mime) {
-		PublicInbox::View::index_entry($fh, $mime, $level, $state);
-	} else {
+
+	unless (mime_dump($fh, $git, $node->message, $level, $state)) {
 		my $mid = $node->messageid;
 		$fh->write(PublicInbox::View::ghost_table('', $mid, $level));
 	}
@@ -295,7 +330,7 @@ sub qs_html {
 		$qs .= "&amp;r";
 	}
 	if (my $x = $self->{x}) {
-		$qs .= "&amp;x=$x" if ($x eq 't' || $x eq 'A');
+		$qs .= "&amp;x=$x" if ($x =~ /\A(?:A|t|f)\z/);
 	}
 	$qs;
 }
-- 
EW


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

end of thread, other threads:[~2015-09-13 23:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-13 22:35 [PATCH 1/3] feed: consolidate updated tag generation Eric Wong
2015-09-13 22:35 ` [PATCH 2/3] searchview: implement Atom feed for search results Eric Wong
2015-09-13 22:35 ` [PATCH 3/3] view: add Atom links in headers for per-message links Eric Wong
2015-09-13 22:37 ` [PATCH 0/3] expand Atom feeds to search results Eric Wong
2015-09-13 23:19   ` [REJECT 4/3] searchview: implement flat view for full message Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).