如何使用RSS:Maker在RSS 2.0提要中生成元素?

时间:2021-12-18 00:59:24

I'm using Ruby 1.9.3 RSS::Maker module to generate a RSS 2.0 feed for a podcast. I'd like to start including a <content:encoded> element for show notes. This is my code for generating the RSS.

我正在使用Ruby 1.9.3 RSS :: Maker模块为播客生成RSS 2.0源。我想开始为show notes添加 元素。这是我生成RSS的代码。

s3_bucket = AWS::S3::Bucket.find(options[:bucket])

content = RSS::Maker.make(version) do |m|
        m.channel.title = options[:title]
        m.channel.link = options[:link]
        m.channel.description = options[:desc]
        m.channel.language = options[:language]
        m.channel.itunes_image = options[:image]
        m.items.do_sort = true

        s3_bucket.select{|object| object.key =~ /[\s\w]+\.(m4b|mp3|m4a|ogg|aac)/}.each do |audio|
                i = m.items.new_item
                i.link = audio.url(:authenticated => false)  
                i.title = audio.key.split(".")[0]
                i.author = options[:author]
                i.pubDate = audio.last_modified
                i.guid.content = audio.etag
                i.enclosure.url = i.link
                i.enclosure.length = audio.content_length
                i.enclosure.type = audio.content_type
                # Insert content:encoded code here
  end 
end

For generating the <content:encoded> element I've tried:

为了生成 元素,我尝试过:

i.encoded :content audio.metadata[:content]

i.encoded:content audio.metadata [:content]

i.encoded :content, audio.metadata[:content]

i.encoded:content,audio.metadata [:content]

i.content = audio.metadata[:content]

i.content = audio.metadata [:content]

i.content.encoded = audio.metadata[:content]

i.content.encoded = audio.metadata [:content]

i.encoded = audio.metadata[:content]

i.encoded = audio.metadata [:content]

i.encoded.content = audio.metadata[:content]

i.encoded.content = audio.metadata [:content]

None of these work and most throw a NoSuchMethod exception - which is not surprising based on the documentation of the RSS::Maker module.

这些都不起作用,并且大多数都会抛出NoSuchMethod异常 - 根据RSS :: Maker模块的文档,这并不奇怪。

Is there a way using RSS::Maker to add arbitrary elements with a namespace?

有没有办法使用RSS :: Maker添加名称空间的任意元素?

1 个解决方案

#1


1  

You’re looking for i.content_encoded.

你正在寻找i.content_encoded。

The documentation isn’t too great, so I used i.methods to get a list of methods I can use on feed items. methods works on all objects.

文档不是很好,所以我使用i.methods获取了我可以在feed项上使用的方法列表。方法适用于所有对象。

The list is quite long, so you most likely only want to show methods you can write to, i.e. something like this:

列表很长,所以你很可能只想显示你可以写的方法,比如这样:

RSS::Maker.make("2.0") do |ma|
  puts ma.items.new_item.methods.keep_if { |m|
    m.to_s.end_with?("=")
  }.join("\n")
end

#1


1  

You’re looking for i.content_encoded.

你正在寻找i.content_encoded。

The documentation isn’t too great, so I used i.methods to get a list of methods I can use on feed items. methods works on all objects.

文档不是很好,所以我使用i.methods获取了我可以在feed项上使用的方法列表。方法适用于所有对象。

The list is quite long, so you most likely only want to show methods you can write to, i.e. something like this:

列表很长,所以你很可能只想显示你可以写的方法,比如这样:

RSS::Maker.make("2.0") do |ma|
  puts ma.items.new_item.methods.keep_if { |m|
    m.to_s.end_with?("=")
  }.join("\n")
end