unofficial mirror of meta@public-inbox.org
 help / color / mirror / 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

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

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