From f0a0679f7ec71d6ae4969d39da4d6be84147fcb4 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Fri, 28 Jun 2019 00:17:10 +0200 Subject: [PATCH] page: prefer meta description as article teaser --- article.inc.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/article.inc.php b/article.inc.php index 336511e..e3a3ee8 100644 --- a/article.inc.php +++ b/article.inc.php @@ -82,8 +82,20 @@ class ArchiveArticle } function teaser() { - if (preg_match('{

(.*?)

}s', $this->story, $bodyp)) { - return $bodyp[1]; + if (preg_match('{ + ]* content="([^">]*)" + }x', $this->preface, $meta)) { + # prefer specific page description if found (assume before title) + #TODO: strip from body contents + return $meta[1]; + } + if (preg_match('{ + (?: \s+ | | ]*> )*

(.*?)

+ }sx', $this->raw, $bodyp, PREG_OFFSET_CAPTURE)) { + # fallback paragraph contents following the page header + if ($bodyp[1][1] < 256) { + return $bodyp[1][0]; + } } } -- 2.30.0