List Info

Thread: valid rss feed help with correct date output




valid rss feed help with correct date output
user name
2006-10-25 23:08:11
Updated /util/output_for_rss.mc     with correct date
output:

<?xml version="1.0"
encoding="utf-8"?>

<rdf:RDF
xmlns:rdf="htt
p://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.
0/"
xmlns:cc="http://web.resource
.org/cc/"
xmlns:taxo="http:
//purl.org/rss/1.0/modules/taxonomy/"
xmlns:dc="http://purl.or
g/dc/elements/1.1/"
xmlns:syn="ht
tp://purl.org/rss/1.0/modules/syndication/"
xmlns:admin="http://webns.net/mvcb/&q
uot;
 >

   <channel rdf:about="http://thetyee.ca<%
$story->get_primary_uri %>">
     <title><![CDATA[<% $story->get_title
%>]]></title>
     <link>http://thetyee.ca<%
$story->get_uri %></link>
   <description><![CDATA[<%
$story->get_data('deck') || $story- 
 >get_description ||
$story->get_data('display_paragraph') %>]]></ 
description>
     <dc:language>en</dc:language>
     <dc:rights>Copyright <%
Bric::Util::Time::strfdate(time, '%Y',  
1) %> TheTyee.ca </dc:rights>
     <dc:publisher>TheTyee.ca (mailto:editorthetyee.ca)</dc:publisher>
     <dc:creator>TheTyee.ca (mailto:editorthetyee.ca)</dc:creator>
     <dc:date><% Bric::Util::Time::strfdate(undef,
'%Y-%m-%dT%H:%M:% 
SZ') %></dc:date>

     <image rdf:resource="http://thetyee.ca/images/ 
tyee_small_icon.png" />


     <items>
       <rdf:Seq>
% for my $doc (docs) {
         <rdf:li rdf:resource="http://thetyee.ca<%
$doc- 
 >get_primary_uri %>" />
% }
       </rdf:Seq>
     </items>
   </channel>
% for my $doc (docs) {
%     my $url = 'http://thetyee.ca' .
$doc->get_primary_uri;
%     my $elem = $doc->get_element;
%     my $title = $doc->get_title;
%     my $description = $elem->get_data('deck') ||
$elem->get_data 
('teaser') || $elem->get_data('paragraph');


<%perl>
       my $contributors = $m->scomp(
       '/util/contributor_list_for_rss.mc',
        asset   => $doc,
        format  => '%f% M% l%, s',
        default => ''
   );
</%perl>
%     # Damn RSS readers don't recognize XHTML in the title.
Convert  
<q> and
%     # strip out other tags.
%     $title =~ s|</q>|&#x201d;|g if $title =~
s|<q>|&#x201c;|g;
%     $title =~ s|</?[^>]+>||g;
%     $description =~ s|</q>|&#x201d;|g if
$description =~ s|<q>| 
&#x201c;|g;
%     $description =~ s|</?[^>]+>||g;
%     my $media_container =
$doc->get_container('related_media');
%     my $image_caption =
$media_container->get_data('caption');
%     if($image_caption) {
%     $image_caption =~ s|</q>|&#x201d;|g if
$image_caption =~ s|<q>| 
&#x201c;|g;
%     $image_caption =~ s|</?[^>]+>||g;
%     }
%           if($media_container){
%              my $image =
$media_container->get_related_media;
%              my $thumb = $m->comp('/util/thumbnail.mc',
image =>  
$image);
%              my $thumb_uri = 'http://thetyee.ca'.$thumb->g
et_uri;
             <image rdf:about="<% $thumb_uri
%>">
%             if($image_caption){
                 <title><![CDATA[<%
$image_caption %>]]></title>
%             }else{
                 <title><![CDATA[<% $title
%>]]></title>
%             }
               <link><% $url %></link>
               <url><% $thumb_uri %></url>
             </image>
%            }
   <item rdf:about="<% $url %>">
     <title><![CDATA[<% $title
%>]]></title>
     <link><% $url %></link>
    <description><![CDATA[<% $description
%>]]></description>
    <dc:date><% Bric::Util::Time::datetime(
        $doc->get_cover_date(
            Bric::Config::ISO_8601_FORMAT
       
))->set_time_zone('UTC')->strftime('%Y-%m-%dT%H:%M:%SZ
')
    %></dc:date>
%  my keywords = $doc->get_keywords;
%    if (keywords){
%       foreach $_ (keywords){
         <dc:subject><![CDATA[ <%
$_->get_name %> ]]></dc:subject>
%       }
%    }

    <% $contributors %>
   </item>
% }
</rdf:RDF>
<%args>
docs
$title => undef
</%args>
<%doc>



-----------------


And here is the utility template-
contributor_list_for_rss.mc (based  
on David Wheeler's contributor_list.mc)


<%once>;
my $full_name_get = sub { $_[0]->get_name($_[1]) };
</%once>
<%args>
$format  => '%p% f% M% l%, s'
$sort    => undef
$asset   => $story
$default => ''
</%args>
<%init>;
# Get the list of contributors.
my contribs = $asset->get_contributors;
unless (contribs) {
     # If there are no contributors, just output the default
and return.
     #$m->print($default);
     return 0;
}
if ($#contribs == 0) {
     # There's just one contributor. Format and return.
    
$m->print('<dc:creator><![CDATA['.$contribs[0]-&
gt;get_name 
($format).']]></dc:creator>');
     return 1;
}
if ($sort) {
     # We need to resort them.
     my $get = $sort eq 'full_list' ? sub {
$_[0]->get_name($format) } :
      
Bric::Util::Grp::Parts::Member::Contrib->my_meths->{$s
ort} 
;
     contribs = sort { lc $get->($a) cmp lc
$get->($b) } contribs;
}

# Output the list.
foreach $_ (contribs){
$m->print('<dc:creator><![CDATA[');
$m->print($_->get_name($format));
$m->print( ']]></dc:creator>');
}


return 1;
</%init>

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )