Skip to content

Commit

Permalink
Fix MondeDiplo empty date
Browse files Browse the repository at this point in the history
  • Loading branch information
Simounet committed Jan 15, 2025
1 parent eadea24 commit f6bdeca
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions bridges/MondeDiploBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,28 @@ public function collectData()

foreach ($html->find('div.unarticle') as $article) {
$element = $article->parent();
$title = $element->find('h3', 0)->plaintext;
$datesAuteurs = $element->find('div.dates_auteurs', 0)->plaintext;
$titleElement = $element->find('h3', 0);
if (!$titleElement) {
continue;
}
$title = $titleElement->plaintext;
$datesAuteursElement = $element->find('div.dates_auteurs', 0);
$datesAuteurs = is_null($datesAuteursElement) ? '' : $element->find('div.dates_auteurs', 0)->plaintext;
$item = [];
$item['uri'] = urljoin(self::URI, $element->href);
$item['title'] = $this->cleanText($title) . ' - ' . $this->cleanText($datesAuteurs);
$item['title'] = $this->getItemTitle($title, $datesAuteurs);
$item['content'] = $this->cleanText(str_replace([$title, $datesAuteurs], '', $element->plaintext));

$this->items[] = $item;
}
}

private function getItemTitle($title, $datesAuteurs)
{
$itemTitle = $this->cleanText($title);
if (strlen($datesAuteurs) > 0) {
$itemTitle .= ' - ' . $this->cleanText($datesAuteurs);
}
return $itemTitle;
}
}

0 comments on commit f6bdeca

Please sign in to comment.