I'm a pretty lousy website content editor, especially when I'm spread thin between a number of resources I need to maintain. I'm doing better now at updating my weblog, but of course that means fewer updates on other websites I help to maintain, like the Daisy website. Doing more with less, was my idea, hence I started toying around this afternoon with syndicating blog posts from my blog to a website managed by the Daisy Wiki.
First, I set up a separate Atom feed for posts in the "daisy" category in Movable Type. I already did this for my Dutch/English posts, so I already knew how to do that. My Atom feed CDATA-escapes blog post content, so I needed some way to parse sections of non-XML content into XHTML. Cocoon of course came to the rescue, with the HTMLTransformer. Thanks, Gianugo!
So all I needed to do was add this little sitemap to Daisy (this is documented, BTW):
<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<map:components>
<map:transformers>
<map:transformer name="htmltransformer"
src="org.apache.cocoon.transformation.HTMLTransformer"/>
</map:transformers>
</map:components>
<map:views>
</map:views>
<map:resources>
</map:resources>
<map:pipelines>
<map:pipeline internal="true" type="noncaching">
<map:match pattern="daisy-news">
<map:generate src="/home/blogs/stevenn/atom-daisy.xml"/>
<map:transform type="htmltransformer">
<map:parameter name="tags" value="content"/>
</map:transform>
<map:transform type="xalan" src="news2html.xsl"/>
<map:serialize type="xml"/>
</map:match>
</map:pipeline>
<map:pipeline type="noncaching">
</map:pipeline>
</map:pipelines>
</map:sitemap>
After that, I created a very simple stylesheet which copies the entries' contents out of the feed:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://purl.org/atom/ns#">
<xsl:template match="/">
<div>
<xsl:for-each select="/atom:feed/atom:entry">
<h2><xsl:value-of select="atom:title"/></h2>
<xsl:copy-of select="atom:content/html/body/*"/>
<p style="text-align: right; color: #999; font-size: 80%;">
Originally blogged by <xsl:value-of select="atom:author/atom:name"/> on
<a href="{atom:link/@href}"><xsl:value-of select="atom:issued"/></a>.
</p>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
Then, the only thing left to do was to insert a "document include" into the news page, and I was all set:
<pre class="include">cocoon:/ext/daisy-news</pre>
This way, when I update my blog with Daisy news, it'll automatically appear on the Daisy website as well. Laziness is a virtue!
TrackBack URL for this entry:
http://blogs.cocoondev.org/MT/mt-tb.cgi/2082