From: Mischa POSLAWSKY Date: Thu, 27 Jun 2019 22:17:10 +0000 (+0200) Subject: page: prefer meta description as article teaser X-Git-Tag: v4.0~14 X-Git-Url: http://git.shiar.net/minimedit.git/commitdiff_plain/f0a0679f7ec71d6ae4969d39da4d6be84147fcb4 page: prefer meta description as article teaser --- 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]; + } } }