hammond-data::parser: Prefer itunes_summary over item.description if it exists. Finishes #20.
This commit is contained in:
parent
ada73a616f
commit
1f0a2b5c6c
@ -38,15 +38,20 @@ pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result<NewEpisode> {
|
|||||||
if item.title().is_none() {
|
if item.title().is_none() {
|
||||||
bail!("No title specified for the item.")
|
bail!("No title specified for the item.")
|
||||||
}
|
}
|
||||||
|
|
||||||
let title = item.title().unwrap().trim().to_owned();
|
let title = item.title().unwrap().trim().to_owned();
|
||||||
let description = item.description()
|
|
||||||
.map(|s| replace_extra_spaces(&ammonia::clean(s)));
|
|
||||||
let guid = item.guid().map(|s| s.value().trim().to_owned());
|
let guid = item.guid().map(|s| s.value().trim().to_owned());
|
||||||
|
|
||||||
let x = item.enclosure().map(|s| url_cleaner(s.url()));
|
let summary = item.itunes_ext().map(|s| s.summary()).and_then(|s| s);
|
||||||
// FIXME: refactor
|
let description = if summary.is_some() {
|
||||||
let uri = if x.is_some() {
|
summary.map(|s| replace_extra_spaces(&ammonia::clean(s)))
|
||||||
x
|
} else {
|
||||||
|
item.description()
|
||||||
|
.map(|s| replace_extra_spaces(&ammonia::clean(s)))
|
||||||
|
};
|
||||||
|
|
||||||
|
let uri = if let Some(url) = item.enclosure().map(|s| url_cleaner(s.url())) {
|
||||||
|
Some(url)
|
||||||
} else if item.link().is_some() {
|
} else if item.link().is_some() {
|
||||||
item.link().map(|s| url_cleaner(s))
|
item.link().map(|s| url_cleaner(s))
|
||||||
} else {
|
} else {
|
||||||
@ -275,8 +280,9 @@ mod tests {
|
|||||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||||
|
|
||||||
let firstitem = channel.items().first().unwrap();
|
let firstitem = channel.items().first().unwrap();
|
||||||
let descr = "<p>A reporter finds that homes meant to replace New York’s troubled \
|
let descr =
|
||||||
psychiatric hospitals might be just as bad.</p>";
|
"A reporter finds that homes meant to replace New York’s troubled psychiatric \
|
||||||
|
hospitals might be just as bad.";
|
||||||
let ep = new_episode(&firstitem, 0).unwrap();
|
let ep = new_episode(&firstitem, 0).unwrap();
|
||||||
|
|
||||||
let expected = NewEpisodeBuilder::default()
|
let expected = NewEpisodeBuilder::default()
|
||||||
@ -297,9 +303,9 @@ mod tests {
|
|||||||
let second = channel.items().iter().nth(1).unwrap();
|
let second = channel.items().iter().nth(1).unwrap();
|
||||||
let ep = new_episode(&second, 0).unwrap();
|
let ep = new_episode(&second, 0).unwrap();
|
||||||
let descr =
|
let descr =
|
||||||
"<p>Jonathan Allen and Amie Parnes didn’t know their book would be called \
|
"Jonathan Allen and Amie Parnes didn’t know their book would be called \
|
||||||
‘Shattered,’ or that their extraordinary access would let them chronicle the \
|
‘Shattered,’ or that their extraordinary access would let them chronicle the \
|
||||||
mounting signs of a doomed campaign.</p>";
|
mounting signs of a doomed campaign.";
|
||||||
|
|
||||||
let expected =
|
let expected =
|
||||||
NewEpisodeBuilder::default()
|
NewEpisodeBuilder::default()
|
||||||
@ -356,12 +362,12 @@ mod tests {
|
|||||||
let second = channel.items().iter().nth(1).unwrap();
|
let second = channel.items().iter().nth(1).unwrap();
|
||||||
let ep = new_episode(&second, 0).unwrap();
|
let ep = new_episode(&second, 0).unwrap();
|
||||||
|
|
||||||
let descr = "<p>The Gnome project is about to solve one of our audience's biggest \
|
let descr =
|
||||||
Wayland’s concerns. But as the project takes on a new level of relevance, \
|
"The Gnome project is about to solve one of our audience's biggest Wayland’s \
|
||||||
decisions for the next version of Gnome have us worried about the \
|
concerns. But as the project takes on a new level of relevance, decisions for the \
|
||||||
future.</p>\n<p>Plus we chat with Wimpy about the Ubuntu Rally in NYC, \
|
next version of Gnome have us worried about the future.\nPlus we chat with Wimpy \
|
||||||
Microsoft’s sneaky move to turn Windows 10 into the “ULTIMATE LINUX \
|
about the Ubuntu Rally in NYC, Microsoft’s sneaky move to turn Windows 10 into the \
|
||||||
RUNTIME”, community news & more!</p>";
|
“ULTIMATE LINUX RUNTIME”, community news & more!";
|
||||||
|
|
||||||
let expected = NewEpisodeBuilder::default()
|
let expected = NewEpisodeBuilder::default()
|
||||||
.title("Gnome Does it Again | LUP 213")
|
.title("Gnome Does it Again | LUP 213")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user