fix(cvedetails,tldrtech) (#3735)

This commit is contained in:
Dag 2023-10-10 21:41:57 +02:00 committed by GitHub
parent 143f90da60
commit b6a9baff94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 79 deletions

View file

@ -35,7 +35,10 @@ class TldrTechBridge extends BridgeAbstract
public function collectData()
{
$html = getSimpleHTMLDOM(self::URI . $this->getInput('topic') . '/archives');
$topic = $this->getInput('topic');
$limit = $this->getInput('limit');
$url = self::URI . $topic . '/archives';
$html = getSimpleHTMLDOM($url);
$entries_root = $html->find('div.content-center.mt-5', 0);
$added = 0;
foreach ($entries_root->children() as $child) {
@ -46,22 +49,25 @@ class TldrTechBridge extends BridgeAbstract
$date_items = explode('/', $child->href);
$date = strtotime(end($date_items));
$this->items[] = [
'uri' => self::URI . $child->href,
'title' => $child->plaintext,
'uri' => self::URI . $child->href,
'title' => $child->plaintext,
'timestamp' => $date,
'content' => $this->parseEntry(self::URI . $child->href)
'content' => $this->extractContent(self::URI . $child->href),
];
$added++;
if ($added >= $this->getInput('limit')) {
if ($added >= $limit) {
break;
}
}
}
private function parseEntry($uri)
private function extractContent($url)
{
$html = getSimpleHTMLDOM($uri);
$html = getSimpleHTMLDOM($url);
$content = $html->find('div.content-center.mt-5', 0);
if (!$content) {
return '';
}
$subscribe_form = $content->find('div.mt-5 > div > form', 0);
if ($subscribe_form) {
$content->removeChild($subscribe_form->parent->parent);