[GithubSearchBridge] Fix content parsing, add tags if present (#803)

* [GithubSearchBridge] Fix content parsing, add tags if present

* [GithubSearchBridge] Add categories (from tags)
This commit is contained in:
Corentin Garcia 2018-09-09 21:30:29 +02:00 committed by Teromene
parent 55b36b0455
commit 111c45d010

View file

@ -34,13 +34,29 @@ class GithubSearchBridge extends BridgeAbstract {
$title = $element->find('h3', 0)->plaintext; $title = $element->find('h3', 0)->plaintext;
$item['title'] = $title; $item['title'] = $title;
if (count($element->find('p')) == 2) { // Description
$content = $element->find('p', 0)->innertext; if (count($element->find('p.d-inline-block')) != 0) {
$content = $element->find('p.d-inline-block', 0)->innertext;
} else{ } else{
$content = ''; $content = 'No description';
} }
$item['content'] = $content;
// Tags
$content = $content . '<br />';
$tags = $element->find('a.topic-tag');
$tags_array = array();
if (count($tags) != 0) {
$content = $content . 'Tags : ';
foreach($tags as $tag_element) {
$tag_link = 'https://github.com' . $tag_element->href;
$tag_name = trim($tag_element->innertext);
$content = $content . '<a href="' . $tag_link . '">' . $tag_name . '</a> ';
array_push($tags_array, $tag_element->innertext);
}
}
$item['categories'] = $tags_array;
$item['content'] = $content;
$date = $element->find('relative-time', 0)->datetime; $date = $element->find('relative-time', 0)->datetime;
$item['timestamp'] = strtotime($date); $item['timestamp'] = strtotime($date);