From 111c45d0100b5f11a544c47b7bc020ac5342b6eb Mon Sep 17 00:00:00 2001 From: Corentin Garcia Date: Sun, 9 Sep 2018 21:30:29 +0200 Subject: [PATCH] [GithubSearchBridge] Fix content parsing, add tags if present (#803) * [GithubSearchBridge] Fix content parsing, add tags if present * [GithubSearchBridge] Add categories (from tags) --- bridges/GithubSearchBridge.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bridges/GithubSearchBridge.php b/bridges/GithubSearchBridge.php index d3a615b5..fe8a721a 100644 --- a/bridges/GithubSearchBridge.php +++ b/bridges/GithubSearchBridge.php @@ -34,13 +34,29 @@ class GithubSearchBridge extends BridgeAbstract { $title = $element->find('h3', 0)->plaintext; $item['title'] = $title; - if (count($element->find('p')) == 2) { - $content = $element->find('p', 0)->innertext; + // Description + if (count($element->find('p.d-inline-block')) != 0) { + $content = $element->find('p.d-inline-block', 0)->innertext; } else{ - $content = ''; + $content = 'No description'; } - $item['content'] = $content; + // Tags + $content = $content . '
'; + $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 . '' . $tag_name . ' '; + array_push($tags_array, $tag_element->innertext); + } + } + + $item['categories'] = $tags_array; + $item['content'] = $content; $date = $element->find('relative-time', 0)->datetime; $item['timestamp'] = strtotime($date);