From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 05/11] feed: extract atom header generation
Date: Tue, 1 Sep 2015 08:55:22 +0000 [thread overview]
Message-ID: <1441097728-31950-5-git-send-email-e@80x24.org> (raw)
In-Reply-To: <1441097728-31950-1-git-send-email-e@80x24.org>
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(<?xml version="1.0" encoding="us-ascii"?>\n) .
+ qq{<feed\nxmlns="http://www.w3.org/2005/Atom">} .
+ qq{<title$type>$title</title>} .
+ qq(<link\nhref="$feed_opts->{url}"/>) .
+ qq(<link\nrel="self"\nhref="$feed_opts->{atomurl}"/>) .
+ qq(<id>mailto:$feed_opts->{id_addr}</id>);
+}
+
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(<?xml version="1.0" encoding="us-ascii"?>\n) .
- qq{<feed\nxmlns="http://www.w3.org/2005/Atom">} .
- qq{<title$type>$title</title>} .
- qq{<link\nhref="$url"/>} .
- qq{<link\nrel="self"\nhref="$atomurl"/>} .
- qq{<id>mailto:$addr</id>};
-
+ 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
next prev parent reply other threads:[~2015-09-01 8:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-01 8:55 [PATCH 01/11] search: reduce redundant doc data Eric Wong
2015-09-01 8:55 ` [PATCH 02/11] search: allow querying all mail with '' Eric Wong
2015-09-01 8:55 ` [PATCH 03/11] search: show newest results first Eric Wong
2015-09-01 8:55 ` [PATCH 04/11] feed: use updated date based on git commit date Eric Wong
2015-09-01 8:55 ` Eric Wong [this message]
2015-09-01 8:55 ` [PATCH 06/11] implement per-thread Atom feeds Eric Wong
2015-09-01 9:30 ` [13/11 PATCH] feed: fix <updated> tag in Atom feed Eric Wong
2015-09-01 8:55 ` [PATCH 07/11] www: compile mbox regexp only once Eric Wong
2015-09-01 8:55 ` [PATCH 08/11] www: root atom feed is "new.atom" and not "atom.xml" Eric Wong
2015-09-01 8:55 ` [PATCH 09/11] completely revamp URL structure to shorten permalinks Eric Wong
2015-09-01 8:55 ` [PATCH 10/11] view: drop extra '</a>' tag Eric Wong
2015-09-01 8:55 ` [PATCH 11/11] view: more robust link generation Eric Wong
2015-09-01 9:08 ` [PATCH 12/11] view: add missing space 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=1441097728-31950-5-git-send-email-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.
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).