extra rss elements
William Morgan
wmorgan-hobix-is-the-way at masanjin.net
Thu Sep 23 08:59:56 EDT 2004
Dear why and the rest,
Here's a simple patch to rss.rb to allow for adding extra fields to the RSS
feed. I'm using this right now to add Creative Commons licensing information,
as described in
http://creativecommons.org/technology/usingmarkup
and
http://backend.userland.com/creativeCommonsRssModule.
With this patch, I add the following in hobix.yaml:
- hobix/out/rss:
namespaces:
creativeCommons: http://backend.userland.com/creativeCommonsRssModule
elements:
creativeCommons:license: http://creativecommons.org/licenses/by-nc-sa/2.\0/
If people like it, I will try and extend this idea to the atom and
okaynews feeds.
(I also changed the page layout such that there's a footer (via SSI,
like the sidebar) which displays the Creative Commons logo and text on
all pages. But that should be easy to figure out how to do.)
--- cut here ---
*** old/rss.rb Wed Sep 22 16:20:28 2004
--- new/rss.rb Thu Sep 23 08:47:43 2004
***************
*** 20,27 ****
module Hobix
module Out
class RSS < Hobix::BaseOutput
! def initialize( weblog )
@path = weblog.skel_path
end
def extension
"rss"
--- 20,29 ----
module Hobix
module Out
class RSS < Hobix::BaseOutput
! def initialize( weblog, params = {} )
@path = weblog.skel_path
+ @extra_ns = params['namespaces']
+ @extra_els = params['elements']
end
def extension
"rss"
***************
*** 52,57 ****
--- 54,69 ----
rssdoc.elements['/rss/channel/link'].text = vars[:weblog].link
rssdoc.elements['/rss/channel/description'].text = vars[:weblog].tagline
rssdoc.elements['/rss/channel/dc:date'].text = Time.now.utc.strftime( "%Y-%m-%dT%H:%M:%S+00:00" )
+
+ @extra_ns.each do |k, v|
+ rssdoc.elements['/rss'].attributes["xmlns:" + k.to_s] = v.to_s
+ end if @extra_ns
+ @extra_els.each do |k, v|
+ extra = REXML::Element.new k.to_s
+ extra.text = v.to_s
+ rssdoc.elements['/rss/channel'].add extra
+ end if @extra_els
+
( vars[:entries] || [vars[:entry]] ).each do |e|
ele = REXML::Element.new 'item'
ele_title = REXML::Element.new 'title'
--- cut here ---
--
William <wmorgan-hobix-is-the-way at masanjin.net>
More information about the Hobix-is-the-way
mailing list