bugfixes #15
1 changed files with 15 additions and 21 deletions
|
@ -45,27 +45,21 @@ pub fn parse_metadata(page: &str) -> Option<Embed> {
|
||||||
let mut meta_title = String::default();
|
let mut meta_title = String::default();
|
||||||
let mut meta_description = String::default();
|
let mut meta_description = String::default();
|
||||||
|
|
||||||
match (title, desc) {
|
if let (None, None) = (title, desc) {
|
||||||
// If both title and description aren't found return None
|
warn!("Couldn't parse any metadata for URL");
|
||||||
(None, None) => {
|
return None;
|
||||||
warn!("Couldn't parse any metadata for URL");
|
}
|
||||||
return None;
|
|
||||||
}
|
if let Some(title) = title {
|
||||||
// Otherwise set the title/description to whatever we find
|
meta_title = title.text().collect();
|
||||||
(Some(title), Some(desc)) => {
|
} else {
|
||||||
meta_title = title.text().collect();
|
warn!("Failed to parse title HTML");
|
||||||
meta_description = desc.value().attr("content").unwrap().to_string();
|
}
|
||||||
}
|
|
||||||
// Handle logging of parse failures
|
if let Some(desc) = desc {
|
||||||
// and set values to whatever we *did* manage to scrape
|
meta_description = desc.value().attr("content").unwrap().to_string();
|
||||||
(Some(title), None) => {
|
} else {
|
||||||
warn!("Failed to parse description HTML");
|
warn!("Failed to parse description HTML");
|
||||||
meta_title = title.text().collect();
|
|
||||||
}
|
|
||||||
(None, Some(desc)) => {
|
|
||||||
warn!("Failed to parse title HTML");
|
|
||||||
meta_description = desc.value().attr("content").unwrap().to_string();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(Embed::new(meta_title, meta_description))
|
Some(Embed::new(meta_title, meta_description))
|
||||||
|
|
Loading…
Reference in a new issue