Skip Menu |

This queue is for tickets about the Bryar CPAN distribution.

Report information
The Basics
Id: 4930
Status: resolved
Priority: 0/
Queue: Bryar

People
Owner: Nobody in particular
Requestors: steve [...] fisharerojo.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 2.1



Subject: Patch to Bryar-2.1 to add Atom Feed
Atom is quickly becoming an important syndication format for bloggers. Most of the top blogging software supports it including MoveableType and Blosxom. This patch adds this functionality to Bryar. I tested this code thoroughly and the Atom feed validated at www.feedvalidator.org.
diff -Naur Bryar-2.1/bryar-newblog myBryar/bryar-newblog --- Bryar-2.1/bryar-newblog 2003-06-14 16:49:53.000000000 -0500 +++ myBryar/bryar-newblog 2004-01-13 20:16:19.000000000 -0600 @@ -209,8 +209,41 @@ </rdf:RDF> EOC +write_file("template.atom", <<EOC); +<?xml version="1.0" encoding="utf-8"?> +<feed version="0.3" xmlns="http://purl.org/atom/ns#"> + <title>[% bryar.config.name %]</title> + <link rel="alternate" type="text/html" + href="[% bryar.config.baseurl %]"/> + <modified>[%documents.first.timepiece.datetime%][% FILTER format("%03d") %][% documents.first.timepiece.tzoffset / 3600 %][%END%]:00</modified> + <author> + <name>[% bryar.config.author %]</name> + </author> +[% FOREACH item = documents %] + <entry> + <title>[% item.title %]</title> + <link rel="alternate" type="text/html" + href="[%bryar.config.baseurl _ "/id_" _ item.id %]"/> + [% idURL = bryar.config.baseurl | replace('http://', '') | replace('/.*', '') %] + <id>tag:[% idURL _ "," _ item.timepiece.year _":id_" _ item.id %]</id> + [% hours = item.timepiece.tzoffset / 3600 %] + [% minutes = (item.timepiece.tzoffset % (hours * 60 * 60)) / 60 %] + <issued>[% item.timepiece.datetime %][% FILTER format("%03d") %][% hours %][%END%]:[% FILTER format("%02d") %][% minutes %][%END%]</issued> + <modified>[% item.timepiece.datetime %][% FILTER format("%03d") %][% hours %][%END%]:[% FILTER format("%02d") %][% minutes %][%END%]</modified> + <summary type="text/plain"> [% FILTER truncate(252) %] + [% item.content | replace('<.*?>', '') %] + [% END %] + </summary> + <content type="text/html" mode="escaped" xml:lang="en" xml:base="[% bryar.config.baseurl %]"> + <![CDATA[ [% item.content %] ]]> + </content> + </entry> +[% END %] +</feed> +EOC + chmod 0644, $_ for ("bryar.conf", "1.txt", "head.html", "foot.html", - "template.html","template.rss"); + "template.html","template.rss", "template.atom"); print "\nDone. Now you want to probably customize 'bryar.conf'.\n"; print "You should probably also customize template.html, head.html and foot.html\n"; print "Then point your browser at bryar.cgi, and get blogging!\n"; diff -Naur Bryar-2.1/lib/Bryar/Collector.pm myBryar/lib/Bryar/Collector.pm --- Bryar-2.1/lib/Bryar/Collector.pm 2003-08-16 07:28:03.000000000 -0500 +++ myBryar/lib/Bryar/Collector.pm 2004-01-13 20:17:20.000000000 -0600 @@ -38,6 +38,7 @@ my %args = @_; $bryar->{arguments} = \%args; delete $args{xml}; # Not interesting + delete $args{atom}; # Also not interesting if (! keys %args) { # Default operation return $class->collect_current($bryar); } diff -Naur Bryar-2.1/lib/Bryar/Config.pm myBryar/lib/Bryar/Config.pm --- Bryar-2.1/lib/Bryar/Config.pm 2003-08-14 11:13:46.000000000 -0500 +++ myBryar/lib/Bryar/Config.pm 2004-01-13 20:20:10.000000000 -0600 @@ -34,6 +34,7 @@ source => "Bryar::DataSource::FlatFile", name => "My web log", description => "Put a better description here", + author => "Anonymous", baseurl => "", datadir => ".", depth => 1, @@ -199,6 +200,19 @@ return $self->{description}; } +=head2 author + + $self->author(); # Get author + +The author of the blog. + +=cut + +sub author { + my $self = shift; + return $self->{author}; +} + =head2 depth diff -Naur Bryar-2.1/lib/Bryar/Frontend/Base.pm myBryar/lib/Bryar/Frontend/Base.pm --- Bryar-2.1/lib/Bryar/Frontend/Base.pm 2003-08-27 17:09:37.000000000 -0500 +++ myBryar/lib/Bryar/Frontend/Base.pm 2004-01-13 20:21:46.000000000 -0600 @@ -77,6 +77,7 @@ my %args; if (defined $pi[-1] and $pi[-1] eq "xml") { $args{xml} = 1; pop @pi; } + if (defined $pi[-1] and $pi[-1] eq "atom") { $args{atom} = 1; pop @pi; } if (defined $pi[-1] and $pi[-1] =~ /id_(.*)/) { $args{id} = $1; pop @pi; } if (defined $pi[0] and $pi[0] =~ /^([a-zA-Z]\w*)/) { # We have a subblog $args{subblog} = $1; diff -Naur Bryar-2.1/lib/Bryar/Renderer/TT.pm myBryar/lib/Bryar/Renderer/TT.pm --- Bryar-2.1/lib/Bryar/Renderer/TT.pm 2003-08-14 11:14:41.000000000 -0500 +++ myBryar/lib/Bryar/Renderer/TT.pm 2004-01-13 20:23:54.000000000 -0600 @@ -92,7 +92,18 @@ $class->_tt_process("template.rss", @_); } +=head2 generate_atom + Bryar::Renderer::TT->generate_atom + +This method generates an Atom feed from the blog entries passed in + +=cut + +sub generate_atom { + my $class = shift; + $class->_tt_process("template.atom", @_); +} =head1 LICENSE diff -Naur Bryar-2.1/lib/Bryar.pm myBryar/lib/Bryar.pm --- Bryar-2.1/lib/Bryar.pm 2003-12-11 07:54:49.000000000 -0600 +++ myBryar/lib/Bryar.pm 2004-01-13 20:27:00.000000000 -0600 @@ -131,6 +131,15 @@ http://your.blog.com/bryar.cgi/otherblog/2003/May/xml +Also, you can generate Atom feeds from your blog as well: + + http://your.blog.com/bryar.cgi/atom + +Or: + + http://your.blog.com/bryar.cgi/otherblog/2003/May/atom + + =head1 METHODS Now for the programmer's interface to Bryar. @@ -197,6 +206,9 @@ if (exists $args{xml}) { $out = $self->{config}->renderer->generate_rss($self, @documents); $ct = "text/xml"; + } elsif (exists $args{atom}) { + $out = $self->{config}->renderer->generate_atom($self, @documents); + $ct = "text/xml"; } else { $out = $self->{config}->renderer->generate_html($self, @documents); }
[SMPETERS - Tue Jan 13 21:41:30 2004]: Show quoted text
> Atom is quickly becoming an important syndication format for bloggers. > Most of the top blogging software supports it including > MoveableType and Blosxom. This patch adds this functionality to > Bryar. I tested this code thoroughly and the Atom feed validated > at www.feedvalidator.org.
Thanks very much for this. I've actually decided to alter the implementation such that adding more formats like this can be done from "userspace". Now you can say bryar.cgi?format=xml, etc., and register your own formats and skins with the renderer. Your Atom template is one of the default registered formats in Bryar 2.2. Thanks again, Simon