user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/3] feed: consolidate updated tag generation
Date: Sun, 13 Sep 2015 22:35:45 +0000	[thread overview]
Message-ID: <20150913223547.5083-1-e@80x24.org> (raw)

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


             reply	other threads:[~2015-09-13 22:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-13 22:35 Eric Wong [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150913223547.5083-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).