rust-syndication / rss

Library for serializing the RSS web content syndication format
https://crates.io/crates/rss
Apache License 2.0
419 stars 52 forks source link

Automatically add the content namespace to a channel when an item makes use of <content:encoded> (or document the requirement) #105

Closed kitlith closed 3 years ago

kitlith commented 3 years ago

In my latest project, I've been generating RSS feeds from scratch (based off some web scraping). Wrote some code that looks somewhat like:

let channel = rss::ChannelBuilder::default()
    // ...
    .items(chapters.into_iter().map(|chapter|
        rss::ItemBuilder::default()
            // ...
            .content(chapter.content)
            .build().unwrap()
    ))
    .build().unwrap()

and then proceeded to run it through a feed validator and find out that the content namespace has not been added. I had to add it to the channel myself with

.namespaces(
    [("content".to_string(), "http://purl.org/rss/1.0/modules/content/".to_string())]
        .iter()
    .cloned()
    .collect::<HashMap<String, String>>(),
)

This was surprising, and I would prefer if it automatically added the relevant namespace, but it would at least be okay if it was mentioned in the documentation somewhere that I would need to do that.

This issue is based on 1.9.0, but i don't think it's been fixed since looking at the source code. If it has, oops?

andy128k commented 3 years ago

@kitlith Thanks for a report.

Can you try a branch in #107 and check if issue is still present?