From 41320da1196d226aff181f80ddcdf7a8415a7158 Mon Sep 17 00:00:00 2001 From: Andres Rey Date: Sat, 2 Dec 2017 21:06:39 +0000 Subject: Search for excerpt in case it's not found on HTML metadata --- src/Readability.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') 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; -- cgit v1.2.3