From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 801671FD21 for ; Tue, 1 Sep 2015 08:55:29 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 05/11] feed: extract atom header generation Date: Tue, 1 Sep 2015 08:55:22 +0000 Message-Id: <1441097728-31950-5-git-send-email-e@80x24.org> In-Reply-To: <1441097728-31950-1-git-send-email-e@80x24.org> References: <1441097728-31950-1-git-send-email-e@80x24.org> List-Id: We'll be using it for per-thread subscriptions --- lib/PublicInbox/Feed.pm | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index 71042d7..3540e9a 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -32,26 +32,26 @@ sub generate_html_index { # private subs +sub atom_header { + my ($feed_opts) = @_; + my $title = $feed_opts->{description}; + $title = PublicInbox::Hval->new_oneline($title)->as_html; + my $type = index($title, '&') >= 0 ? "\ntype=\"html\"" : ''; + + qq(\n) . + qq{} . + qq{$title} . + qq({url}"/>) . + qq({atomurl}"/>) . + qq(mailto:$feed_opts->{id_addr}); +} + sub emit_atom { my ($cb, $ctx) = @_; my $fh = $cb->([ 200, ['Content-Type' => 'application/xml']]); my $max = $ctx->{max} || MAX_PER_PAGE; my $feed_opts = get_feedopts($ctx); - my $addr = $feed_opts->{address}; - $addr = $addr->[0] if ref($addr); - $addr ||= 'public-inbox@example.com'; - my $title = $feed_opts->{description} || "unnamed feed"; - $title = PublicInbox::Hval->new_oneline($title)->as_html; - my $type = index($title, '&') >= 0 ? "\ntype=\"html\"" : ''; - my $url = $feed_opts->{url} || "http://example.com/"; - my $atomurl = $feed_opts->{atomurl}; - my $x = qq(\n) . - qq{} . - qq{$title} . - qq{} . - qq{} . - qq{mailto:$addr}; - + my $x = atom_header($feed_opts); my $git = PublicInbox::GitCatFile->new($ctx->{git_dir}); each_recent_blob($ctx, sub { my ($path, undef, $ts) = @_; @@ -219,13 +219,18 @@ sub get_feedopts { if (open my $fh, '<', "$ctx->{git_dir}/description") { chomp($rv{description} = <$fh>); close $fh; + } else { + $rv{description} = '($GIT_DIR/description missing)'; } if ($pi_config && defined $listname && $listname ne '') { - foreach my $key (qw(address)) { - $rv{$key} = $pi_config->get($listname, $key) || ""; - } + my $addr = $pi_config->get($listname, 'address') || ""; + $rv{address} = $addr; + $addr = $addr->[0] if ref($addr); + $rv{id_addr} = $addr; } + $rv{id_addr} ||= 'public-inbox@example.com'; + my $url_base; if ($cgi) { my $path_info = $cgi->path_info; -- EW