summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2017-12-02 21:06:39 +0000
committerAndres Rey <[email protected]>2017-12-02 21:06:39 +0000
commit41320da1196d226aff181f80ddcdf7a8415a7158 (patch)
tree22ca04b3fbaf55ee8fe20229033fb31dc1b29cea /src
parentebebe6656fc6cc1794cae0cb427c900a2f6095f5 (diff)
Search for excerpt in case it's not found on HTML metadata
Diffstat (limited to 'src')
-rw-r--r--src/Readability.php10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Readability.php b/src/Readability.php
index 67c9654..f73a860 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -164,6 +164,16 @@ class Readability
$result = $this->postProcessContent($result);
+ // If we haven't found an excerpt in the article's metadata, use the article's
+ // first paragraph as the excerpt. This can be used for displaying a preview of
+ // the article's content.
+ if (!$this->getExcerpt()) {
+ $paragraphs = $result->getElementsByTagName('p');
+ if ($paragraphs->length > 0) {
+ $this->setExcerpt(trim($paragraphs->item(0)->textContent));
+ }
+ }
+
$this->setContent($result->C14N());
return true;