From 4f5e01802fbfaf46e34ba3fea9a4faca639f6ec4 Mon Sep 17 00:00:00 2001 From: froge Date: Sun, 8 Oct 2023 04:06:25 +1000 Subject: [PATCH] Fix bug that broke partial metadata parsing --- src/embeds.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/embeds.rs b/src/embeds.rs index 63aed72..1de2d15 100644 --- a/src/embeds.rs +++ b/src/embeds.rs @@ -57,8 +57,15 @@ pub fn parse_metadata(page: &str) -> Option { meta_description = desc.value().attr("content").unwrap().to_string(); } // Handle logging of parse failures - (Some(_), None) => warn!("Failed to parse description HTML"), - (None, Some(_)) => warn!("Failed to parse title HTML"), + // and set values to whatever we *did* manage to scrape + (Some(title), None) => { + 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))