nieuws: first paragraph teaser as page description
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 11 Feb 2019 00:09:30 +0000 (01:09 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 2 Mar 2019 13:22:31 +0000 (14:22 +0100)
Enable previews in social media links.  Also used in search results.

head.inc.php
nieuws.inc.php
nieuws/index.php

index ff6397197f01bfb405bfaf14690ea06266117071..1e57e666a369877183a7326fa472bf9a716544db 100644 (file)
@@ -4,6 +4,9 @@
        <meta charset="utf-8" />
 <?php if (!empty($Place['title'])) { ?>
        <title><?= htmlspecialchars($Place['title']) ?></title>
+<?php } ?>
+<?php if (!empty($Place['description'])) { ?>
+       <meta name="description" property="og:description" content="<?= strip_tags($Place['description']) ?>" />
 <?php } ?>
        <meta name="viewport" content="width=device-width" />
        <!--[if lt IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script><![endif]-->
index 40313e4b868eaca401db2331b303ae17261015b4..6d84d1ac54b5930a19f2f26af75dcc13a96d6c14 100644 (file)
@@ -86,6 +86,13 @@ class ArchiveArticle
                return $rest;
        }
 
+       function teaser()
+       {
+               if (preg_match('{<p>(.*?)</p>}s', $this->body, $bodyp)) {
+                       return $bodyp[1];
+               }
+       }
+
        function img()
        {
                $this->body;
index 4ffaa23d614be2d689a63190a46bd1f4cf2c84c1..71048d50cc64228b11989ebd56d83f17997d891a 100644 (file)
@@ -12,6 +12,7 @@ if ($page and !is_numeric($page)) {
        $edit = !empty($User['admin']) ? htmlspecialchars(@$_GET['edit']) : NULL;
        $article = new ArchiveArticle("$Page$Args.html");
        $Place['title'] = $edit ?: $article->title;
+       $Place['description'] = $article->teaser;
        $Place[1] = ' <small class="date">'.$article->date.'</small>';
        print preg_replace('{(?<=<h2>)(.*?)(?=</h2>)}', ($edit ?: '\1').' [[1]]', ob_get_clean());
        if ($article->file and $article->image) {