1
0
Fork 0
mirror of https://gitlab.com/news-flash/article_scraper.git synced 2025-07-07 16:15:32 +02:00

fix using parent if top candidate is only child

This commit is contained in:
Jan Lukas Gernert 2023-03-12 14:20:19 +01:00
parent 14ba2ccb70
commit 11d9657bdd

View file

@ -394,7 +394,7 @@ impl Readability {
// joining logic when adjacent content is actually located in parent's sibling node. // joining logic when adjacent content is actually located in parent's sibling node.
parent_of_top_candidate = top_candidate.get_parent(); parent_of_top_candidate = top_candidate.get_parent();
while Util::has_tag_name(parent_of_top_candidate.as_ref(), "BODY") while !Util::has_tag_name(parent_of_top_candidate.as_ref(), "BODY")
&& parent_of_top_candidate && parent_of_top_candidate
.as_ref() .as_ref()
.map(|n| n.get_child_elements().len() == 1) .map(|n| n.get_child_elements().len() == 1)
@ -422,10 +422,10 @@ impl Readability {
parent_of_top_candidate = top_candidate.get_parent(); parent_of_top_candidate = top_candidate.get_parent();
let siblings = parent_of_top_candidate let siblings = parent_of_top_candidate
.as_ref() .as_ref()
.map(|n| n.get_child_nodes()); .map(|n| n.get_child_elements());
if let Some(siblings) = siblings { if let Some(mut siblings) = siblings {
for mut sibling in siblings { for mut sibling in siblings.drain(..) {
let mut append = false; let mut append = false;
let score = Self::get_content_score(&sibling).unwrap_or(0.0); let score = Self::get_content_score(&sibling).unwrap_or(0.0);