Skip to content

Commit

Permalink
[DevToBridge] Fix bridge (#1699)
Browse files Browse the repository at this point in the history
Fixes full article option not working
  • Loading branch information
VerifiedJoseph authored Aug 12, 2020
1 parent 268ddf1 commit dc36b42
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions bridges/DevToBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,29 @@ public function getIcon() {
}

public function collectData() {

$html = getSimpleHTMLDOMCached($this->getURI())
or returnServerError('Could not request ' . $this->getURI());

$html = defaultLinkTo($html, static::URI);

$articles = $html->find('div.single-article')
$articles = $html->find('div.crayons-story')
or returnServerError('Could not find articles!');

foreach($articles as $article) {
$item = array();

$item['uri'] = $article->find('a[id*=article-link]', 0)->href;
$item['title'] = $article->find('h3', 0)->plaintext;
$item['title'] = $article->find('h2 > a', 0)->plaintext;

// i.e. "Charlie Harrington・Sep 21"
$item['timestamp'] = strtotime(explode('', $article->find('h4 a', 0)->plaintext, 2)[1]);
$item['author'] = explode('', $article->find('h4 a', 0)->plaintext, 2)[0];
$item['timestamp'] = $article->find('time', 0)->datetime;
$item['author'] = $article->find('a.crayons-story__secondary.fw-medium', 0)->plaintext;

// Profile image
$item['enclosures'] = array($article->find('img', 0)->src);

if($this->getInput('full')) {
$fullArticle = $this->getFullArticle($item['uri']);
$item['content'] = <<<EOD
<img src="{$item['enclosures'][0]}" alt="{$item['author']}">
<p>{$fullArticle}</p>
EOD;
} else {
Expand All @@ -80,11 +77,13 @@ public function collectData() {
EOD;
}

$item['categories'] = array_map(function($e){ return $e->plaintext; }, $article->find('div.tags span.tag'));
// categories
foreach ($article->find('a.crayons-tag') as $tag) {
$item['categories'][] = str_replace('#', '', $tag->plaintext);
}

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

}

public function getName() {
Expand All @@ -101,6 +100,10 @@ private function getFullArticle($url) {

$html = defaultLinkTo($html, static::URI);

if ($html->find('div.crayons-article__cover', 0)) {
return $html->find('div.crayons-article__cover', 0) . $html->find('[id="article-body"]', 0);
}

return $html->find('[id="article-body"]', 0);
}
}

0 comments on commit dc36b42

Please sign in to comment.