diff --git a/src/article.rs b/src/article.rs index 3d56213..73bef18 100644 --- a/src/article.rs +++ b/src/article.rs @@ -16,7 +16,7 @@ pub struct Article { impl Article { pub fn save_html(&self, path: &PathBuf) -> Result<(), Error> { if let Some(ref html) = self.html { - if let Ok(()) = std::fs::create_dir_all(&path) { + if let Ok(()) = std::fs::create_dir_all(path) { let mut file_name = match self.title.clone() { Some(file_name) => file_name.replace('/', "_"), None => "Unknown Title".to_owned(), diff --git a/src/full_text_parser/config/config_collection.rs b/src/full_text_parser/config/config_collection.rs index b4a7ff6..5c9ad34 100644 --- a/src/full_text_parser/config/config_collection.rs +++ b/src/full_text_parser/config/config_collection.rs @@ -28,10 +28,7 @@ impl ConfigCollection { if let Some(directory) = directory { // create data dir if it doesn't already exist - if let Err(error) = std::fs::DirBuilder::new() - .recursive(true) - .create(&directory) - { + if let Err(error) = std::fs::DirBuilder::new().recursive(true).create(directory) { log::warn!( "Failed to create user config directory {:?}: {}", directory, diff --git a/src/full_text_parser/mod.rs b/src/full_text_parser/mod.rs index d0e3b4b..7f91996 100644 --- a/src/full_text_parser/mod.rs +++ b/src/full_text_parser/mod.rs @@ -209,17 +209,17 @@ impl FullTextParser { // parse html let parser = Parser::default_html(); - Ok(parser.parse_string(html.as_str()).map_err(|err| { + parser.parse_string(html.as_str()).map_err(|err| { error!("Parsing HTML failed for downloaded HTML {:?}", err); FullTextParserError::Xml - })?) + }) } fn get_xpath_ctx(doc: &Document) -> Result { - Ok(Context::new(doc).map_err(|()| { + Context::new(doc).map_err(|()| { error!("Creating xpath context failed for downloaded HTML"); FullTextParserError::Xml - })?) + }) } async fn parse_single_page( @@ -356,29 +356,26 @@ impl FullTextParser { } fn check_for_thumbnail(context: &Context, article: &mut Article) { - if let Some(thumb) = Self::get_attribute( + if let Ok(thumb) = Self::get_attribute( context, "//meta[contains(@name, 'twitter:image')]", "content", - ) - .ok() + ) { + article.thumbnail_url = Some(thumb); + return; + } + + if let Ok(thumb) = + Self::get_attribute(context, "//meta[contains(@name, 'og:image')]", "content") { article.thumbnail_url = Some(thumb); return; } - if let Some(thumb) = - Self::get_attribute(context, "//meta[contains(@name, 'og:image')]", "content").ok() + if let Ok(thumb) = + Self::get_attribute(context, "//link[contains(@rel, 'image_src')]", "href") { article.thumbnail_url = Some(thumb); - return; - } - - if let Some(thumb) = - Self::get_attribute(context, "//link[contains(@rel, 'image_src')]", "href").ok() - { - article.thumbnail_url = Some(thumb); - return; } } @@ -495,8 +492,7 @@ impl FullTextParser { if is_relative_url { let completed_url = Self::complete_url(article_url, &url)?; - let _ = node - .set_attribute(attribute, completed_url.as_str()) + node.set_attribute(attribute, completed_url.as_str()) .map_err(|_| FullTextParserError::Scrape)?; } }