[LON-CAPA-cvs] cvs: CVSROOT / cvs2rss.pl
albertel
lon-capa-cvs@mail.lon-capa.org
Tue, 11 Oct 2005 22:11:16 -0000
albertel Tue Oct 11 18:11:16 2005 EDT
Modified files:
/CVSROOT cvs2rss.pl
Log:
- I think fixed the problems with HTML in diffs
Index: CVSROOT/cvs2rss.pl
diff -u CVSROOT/cvs2rss.pl:1.1 CVSROOT/cvs2rss.pl:1.2
--- CVSROOT/cvs2rss.pl:1.1 Tue Oct 11 15:45:18 2005
+++ CVSROOT/cvs2rss.pl Tue Oct 11 18:11:16 2005
@@ -13,23 +13,18 @@
#
# AddType application/rss+xml .rss
#
-# Important note:
-# If you have html files (or files with html in them) in your CVS Repository, look in your RSS.pm for:
-#
-# $text =~ s/</</g;
-#
-# I suggest commenting out this line because it will screw up this script (I think its a bug in the parser)
-# If you do not, when this script uses XML:RSS's parsefile(), it will mess up any <descriptions> that
-# contain HTML.
-#
# P.S. The "other" cvs2rss.pl isn't really cvs2rss, it is more like cvs2xml, boo!
# P.P.S. Parts of this are stolen from commit2rss.rb and the XML::RSS examples.
#
# Version 1.0 - 08.24.04 RSS Compliant, no cvs diff capability yet..
# Version 1.1 - 08.31.04 Adding CVS Diff capability
+# Edit by Guy Albertelli, -- corrected the packaging of Entities
+# - commits now <pre>ed
+# - removed html rants
#
use strict;
+use HTML::Entities();
use XML::RSS;
use POSIX;
@@ -37,10 +32,10 @@
my $rssFeed ="/home/loninst/public_html/loncapa.rss";
my $emailDomain = "loncapa.org";
my $channelTitle = "Lon-CAPA RSS Feed";
-my $channelLink = "http://install.loncapa.org/cvs.rss";
+my $channelLink = "http://install.loncapa.org/loncapa.rss";
my $numEntries = 200;
-# Set this to 1 to enable cvs rdiff (is pretty broken if you are diffing html content)
+# Set this to 1 to enable cvs rdiff
my $cvsDiff = 1;
# Leave everything else alone
@@ -87,17 +82,17 @@
# If the old version of the file is not NONE (if it isn't a new file), and if it is a .txt or .java file (that has no html)
# This will rdiff it against the previous version, and include that diff in the rss feed
- if (($title[1] != "NONE") && ($title[0]=~/(.*).(txt|java)$/)){
+ if (($title[1] != "NONE") && ($title[0]=~/(.*).(pm)$/)){
my $tmpFile = "/tmp/diff.$$";
my $cmdLine = "cvs -n rdiff -kk -r " . $title[1] . " -r " . $title[2] . " " . $title[0] . ">" . $tmpFile;
system($cmdLine);
- $description .= "<br /><b>Differences:</b><br />";
+ $description .= "<br /><b>Differences:</b><br /><pre>";
open CVSDIFF, "<" . $tmpFile;
foreach my $line (<CVSDIFF>) {
- chomp($line);
- $description .= $line . "<br />";
+ $description .= &HTML::Entities::encode($line,'<>&"');
}
+ $description .= "</pre>";
unlink($tmpFile);
}
}
@@ -110,11 +105,8 @@
mode => 'insert'
);
-# XML::RSS doesn't like HTML in the XML so Escape the description body with <![CDATA[ ]]>
-# This is messy and stupid, but both XML::RSS and XML are sort of dumb, and I can't figure out a way around it.
-# Certain RSS readers will try and render the HTML regardless of if it is wrapped in a CDATA tag or not so um, deal.
foreach my $element (@{$rss->{'items'}}) {
- $element->{'description'} = "<![CDATA[" . $element->{'description'} . "]]>";
+ $element->{'description'} = &HTML::Entities::encode($element->{'description'},'<>&"');
}
$rss->save($rssFeed);