Skip to content

Commit

Permalink
support links
Browse files Browse the repository at this point in the history
  • Loading branch information
joksas committed Aug 28, 2024
1 parent 3f7de5d commit 9641282
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
name = "goodpod"
readme = "README.md"
repository = "https://github.com/rssblue/goodpod"
version = "0.1.1"
version = "0.1.2"
description = "A crate for generating Podcasting 2.0 feeds."

[dev-dependencies]
Expand Down
16 changes: 16 additions & 0 deletions src/rss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::itunes;
use crate::podcast;
use crate::Language;

use url::Url;
use uuid::Uuid;
use xml::attribute::OwnedAttribute;
use xml::namespace::Namespace;
Expand Down Expand Up @@ -55,6 +56,7 @@ pub struct Channel {
pub language: Option<Language>,
pub last_build_date: Option<chrono::DateTime<chrono::Utc>>,
pub title: Option<String>,
pub link: Option<Url>,

pub itunes_image: Option<itunes::Image>,

Expand Down Expand Up @@ -155,6 +157,20 @@ impl yaserde::YaSerialize for Channel {
.map_err(|e| e.to_string())?;
}

if let Some(link) = &self.link {
writer
.write(xml::writer::XmlEvent::start_element("link"))
.map_err(|e| e.to_string())?;
writer
.write(xml::writer::XmlEvent::characters(
link.as_str().trim_end_matches('/'),
))
.map_err(|e| e.to_string())?;
writer
.write(xml::writer::XmlEvent::end_element())
.map_err(|e| e.to_string())?;
}

if let Some(itunes_image) = &self.itunes_image {
itunes_image.serialize(writer)?;
}
Expand Down
1 change: 1 addition & 0 deletions tests/data/complex-feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<description>My description</description>
<generator>RSS Blue v1.0</generator>
<title>My &lt;strong&gt;title&lt;/strong&gt;</title>
<link>https://example.com</link>
<podcast:funding url="https://www.example.com/donations">Support the show!</podcast:funding>
<podcast:funding url="https://www.example.com/members">Become a member!</podcast:funding>
<podcast:locked owner="[email protected]">no</podcast:locked>
Expand Down
2 changes: 2 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use chrono::prelude::*;
use goodpod::*;
use pretty_assertions::assert_eq;
use url::Url;

#[test]
fn serialize_simple_feed() {
Expand Down Expand Up @@ -86,6 +87,7 @@ fn serialize_complex_feed() {
let rss = Rss {
channel: Channel {
title: Some("My <strong>title</strong>".to_string()),
link: Some(Url::parse("https://example.com").unwrap()),
description: Some("My description".to_string()),
generator: Some("RSS Blue v1.0".to_string()),
last_build_date: None,
Expand Down

0 comments on commit 9641282

Please sign in to comment.