From: Matt S Trout <mst@shadowcat.co.uk> Date: Tue, 25 Oct 2011 08:42:35 +0000 (+0000) Subject: make the atom feed valid X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b0df368c0a3e1356522c54a0a358e2e09d9c7c1f;p=scpubgit%2FSCS.git make the atom feed valid --- diff --git a/lib/SCSite/FeedGenerator.pm b/lib/SCSite/FeedGenerator.pm index 981865c..e8e28c1 100644 --- a/lib/SCSite/FeedGenerator.pm +++ b/lib/SCSite/FeedGenerator.pm @@ -18,19 +18,21 @@ sub _config_to_data { my $base_page = $self->pages->get({ path => $config->{base} }); my @entry_pages = $base_page->children(%{$config->{entries}}) ->latest(10)->flatten; + my $updated = (sort map $_->created, @entry_pages)[-1]; +{ %$config, id => $self->_id_for($base_page->path), - web_url => $base_page->path, - feed_url => "/feed/${\$config->{base}}", + web_url => $base_page->path.'/', + feed_url => "/feed/${\$config->{base}}/", + updated => join('T', split(' ',$updated)).'Z', entries => [ map +{ title => $_->title, summary_html => do { use HTML::Tags; - HTML::Tags::to_html_string(<p>, $_->description, </p>) + join '', HTML::Tags::to_html_string(<p>, $_->description, </p>) }, content_html => $_->body, - created => $_->created, + created => join('T', split(' ',$_->created)).'Z', web_url => $_->path, }, @entry_pages ], } @@ -70,6 +72,7 @@ sub _feed_data_to_tags { : ()), ' ', <link rel="alternate" type="text/html" href="${web_url}" />, "\n", ' ', <link rel="self" type="application/atom+xml" href="${feed_url}" />, "\n", + ' ', <updated>, $data->{updated}, </updated>, "\n", ' ', <id>, $data->{id}, </id>, "\n", (map $self->_entry_data_to_tags($_), @{$data->{entries}}), </feed>); @@ -77,19 +80,22 @@ sub _feed_data_to_tags { sub _entry_data_to_tags { my ($self, $data) = @_; - use XML::Tags qw(entry title link id published updated summary content); + use XML::Tags qw( + entry title author name link id published updated summary content + ); my $web_url = $data->{web_url}; ' ', <entry>, "\n", ' ', <title>, $data->{title}, </title>, "\n", + ' ', <author>, <name>, "Shadowcat Staff", </name>, </author>, "\n", ' ', <link href="${web_url}" />, "\n", ' ', <id>, $self->_id_for($data->{web_url}), </id>, "\n", ' ', <published>, $data->{created}, </published>, "\n", ' ', <updated>, ($data->{created}||$data->{updated}), </updated>, "\n", ($data->{summary_html} - ? (' ', <summary type="html">, \($data->{summary_html}), </summary>, "\n") + ? (' ', <summary type="html">, \('<![CDATA['.$data->{summary_html}.']]>'), </summary>, "\n") : () ), - ' ', <content type="html">, \($data->{body_html}), </content>, "\n", + ' ', <content type="html">, \('<![CDATA['.$data->{content_html}.']]>'), </content>, "\n", ' ', </entry>, "\n"; }