Hello, From: Matt Kraai <[EMAIL PROTECTED]> Subject: Re: Debian News RSS Feed Date: Wed, 1 Dec 2004 23:27:59 -0800
> Thanks for the demo code, but we don't use PHP on the official web
> site. It would be best if someone would implement a wml solution.
I implemented the RSS Feed for Debian Weekly News with wml and
<perl>. Similar scheme was found at security/dsa*.rdf.in, I just
modeled on it. There are 2 new files (english/News/weekly/dwn.rdf.in
and english/template/debian/weeklynews/rdf.wml) and patch against the
english/News/weekly/Makefile.
dwn.rdf.in contains the whole of the current issue, as described
in CURRENT-ISSUE-IS. Each item does not have a parmlink, so all
rdf:about attributes are just same, however, this attribute seems to
be necessary. It may be better to add such as index.??.html, but this
would be the function of content negotiation, I guess.
rdf.wml provides the functions for splitting the issue into items, and
create <item>s. And optionally, if we can use POSIX::strftime, the
<dc:date> element is more valiable by adding the zone information
(+NN:NN).
* I believe that charset of the feed would prefer to be UTF-8, but now
uses as the same kind of .html(s). The same holds true for dsa feeds.
* Some elements or attributions may be not enough or redundant.
* I just made dwn.{en,ja}.rdf only...
Please test and give me your comments and suggestions.
Regards,
--
Nobuhiro IMAI <[EMAIL PROTECTED]>
Key fingerprint = F39E D552 545D 7C64 D690 F644 5A15 746C BD8E 7106
#use wml::debian::weeklynews::rdf <: my ($dir, $items_ref) = parse_issue('$(ENGLISHDIR)', 'News/weekly', 'CURRENT-ISSUE-IS'); :> <?xml version="1.0" encoding="$(CHARSET)"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xml:lang="$(CUR_ISO_LANG)" > <channel rdf:about="http://www.debian.org/News/weekly/dwn.rdf"> <title><gettext domain="templates">Debian Weekly News</gettext></title> <link>http://www.debian.org/News/weekly/</link> <description> <gettext domain="templates">Debian Weekly News</gettext> </description> <dc:creator>[EMAIL PROTECTED]</dc:creator> <dc:date><: print(join('T', split(' ','$(WML_GEN_ISOTIME)'))); :></dc:date> <items> <rdf:Seq> <protect pass=2> <rdf:li resource="http://www.debian.org/News/weekly/<:= $dir; :>/" /> </protect> </rdf:Seq> </items> </channel> <: dwn_item_list($dir, $items_ref); :> </rdf:RDF>
#use wml::std::tags
#use wml::debian::openrecode
<perl>
sub parse_issue {
my ($eng_dir, $dwndir, $cur_issue) = @_;
open(CURRENT, "$eng_dir/$dwndir/$cur_issue") or return ();
chomp(my $dir = <CURRENT>);
close(CURRENT);
my ($editors, @items);
my $fh = openrecode("./$dir/index.wml", "$eng_dir/$dwndir/$dir/index.wml");
local($/) = "";
while($p = <$fh>){
next if $p =~ /^#use\s/;
$p =~ tr/\r\n/ /;
$p =~ s/\\\s+//g;
$p =~ s/\A\s+//;
$p =~ s/\s+\z//;
my ($title, $content);
if($p =~ m:\A<p>(<strong>(.+?)</strong>)?\s*(.+?)\s*</p>\z:){
$title = (defined $1) ? $2 : 'Editorial of this issue.';
$content = $3;
next unless(defined $title and defined $content);
$content =~ s,\Q$(HOME)/\E,http://www.debian.org/,g;
push(@items, {title => $title, content => $content});
} elsif($p =~ m:\A<ul>\s*<li>(.+)\s*</ul>\z:){
next unless(defined $1);
my $pkg = $1;
$pkg =~ s:</li>::g;
my $pkglist = '<ul><li>' . join('</li><li>', split(/<li>/, $pkg)) .
'</li></ul>';
$items[-1]->{pkglist} = $pkglist;
}
}
close($fh);
return ($dir, [EMAIL PROTECTED]);
}
sub dwn_item_list {
my ($dir, $items_ref) = @_;
my $template = <<'ITEM';
<item rdf:about="%s">
<title>%s</title>
<content:encoded>
<![CDATA[<p>%s</p>%s]]>
</content:encoded>
</item>
ITEM
my $about = "http://www.debian.org/News/weekly/$dir/";
foreach my $item (@{$items_ref}){
my $title = $item->{title};
my $content = $item->{content};
my $pkglist = $item->{pkglist} or '';
printf($template, $about, $title, $content, $pkglist);
}
}
# This should be move into ../ctime.wml, if it is convenient for others.
sub iso8601 {
my $time = shift;
$time = time() unless $time;
use POSIX qw(strftime);
my $t = POSIX::strftime('%Y-%m-%dT%H:%M:%S%z', localtime($time));
substr($t, -2, 0, ':');
return $t;
}
</perl>
Index: Makefile
===================================================================
RCS file: /cvs/webwml/webwml/english/News/weekly/Makefile,v
retrieving revision 1.42
diff -s -u -r1.42 Makefile
--- Makefile 14 Nov 2003 01:11:47 -0000 1.42
+++ Makefile 10 Dec 2004 04:01:20 -0000
@@ -130,13 +130,41 @@
# Have to add to the default clean rule to clean up all the html the
# above target produces.
clean::
+ rm -f $(DWNRDF)
ifeq "$(LANGUAGE)" "zh"
-find . -type f -name \*.$(LANGUAGE)-??.html | xargs rm -f
else
ifeq "$(LANGUAGE)" "ja"
-find . -type f -name \*.$(LANGUAGE).html.tmp | xargs rm -f
+ rm -f $(DWNRDF).tmp
endif
-find . -type f -name \*.$(LANGUAGE).html | xargs rm -f
+endif
+
+ifndef SUBLANG
+DWNRDF := dwn.$(LANGUAGE).rdf
+DESTDWNRDF := $(HTMLDIR)/$(DWNRDF)
+else
+DWNRDF := $(sort $(foreach i,$(SUBLANG),$(subst
dwn,dwn.$(LANGUAGE)-$(i),dwn.rdf)))
+DESTDWNRDF := $(patsubst %.rdf,$(HTMLDIR)/%.rdf,$(DWNRDF))
+endif
+
+$(DWNRDF): $(ENGLISHDIR)/$(CUR_DIR)/dwn.rdf.in \
+ $(ENGLISHDIR)/$(CUR_DIR)/CURRENT-ISSUE-IS \
+ $(wildcard $(shell cat
$(ENGLISHDIR)/$(CUR_DIR)/CURRENT-ISSUE-IS)/index.wml) \
+ $(TEMPLDIR)/weeklynews/rdf.wml $(GETTEXTDEP)
+ $(WML) $(shell egrep '^-D (CUR_|CHAR)' ../../.wmlrc) \
+ $(ENGLISHDIR)/$(CUR_DIR)/dwn.rdf.in
+
+all:: $(DWNRDF)
+
+install:: $(DESTDWNRDF)
+
+$(DESTDWNRDF): $(HTMLDIR)/%: %
+ @test -d $(HTMLDIR) || mkdir -m g+w -p $(HTMLDIR)
+ install -m 644 -p $< $(HTMLDIR)
+ifeq "$(LANGUAGE)" "en"
+ ln -sf dwn.en.rdf $(HTMLDIR)/dwn.rdf
endif
# Need to rebuild the index when anything changes.
pgpdfySA8KQuu.pgp
Description: PGP signature

