multiple meta images for posts

This commit is contained in:
Alex Grintsvayg 2016-07-04 13:07:27 -04:00
parent f019ccaa1f
commit a31fb27387
7 changed files with 27 additions and 31 deletions

View file

@ -236,6 +236,13 @@ class Post
return $this->getPostNum() % $maxStyles + 1;
}
public function getImageUrls()
{
$matches = [];
preg_match_all('/!\[.*?\]\((.*?)\)/', $this->markdown, $matches);
return $matches ? $matches[1] : [];
}
protected function markdownToText($markdown)
{
$replacements = [

View file

@ -17,16 +17,24 @@ class Response
'css' => []
],
// $bodyCssClasses = [],
$metaImg = '';
$metaImages = [];
public static function setMetaDescription($description)
{
static::$metaDescription = $description;
}
public static function setMetaImage($url)
public static function addMetaImage($url)
{
static::$metaImg = $url;
static::$metaImages[] = $url;
}
public static function addMetaImages(array $urls)
{
foreach($urls as $url)
{
static::addMetaImage($url);
}
}
public static function getMetaDescription()
@ -34,9 +42,9 @@ class Response
return static::$metaDescription ?: 'A Content Revolution';
}
public static function getMetaImage()
public static function getMetaImages()
{
return static::$metaImg ?: 'http://lbry.io/img/lbry-dark-1600x528.png';
return static::$metaImages ?: ['https://lbry.io/img/lbry-dark-1600x528.png'];
}
public static function setMetaTitle($title)

View file

@ -14,9 +14,6 @@ class View
{
const LAYOUT_PARAMS = '_layout_params';
protected static $metaDescription = '',
$metaImg = '';
public static function render($template, array $vars = [])
{
if (static::isMarkdown($template))
@ -92,26 +89,6 @@ class View
return '/img/' . $image;
}
public static function setMetaDescription($description)
{
static::$metaDescription = $description;
}
public static function setMetaImage($url)
{
static::$metaImg = $url;
}
public static function getMetaDescription()
{
return static::$metaDescription ?: 'A Content Revolution';
}
public static function getMetaImage()
{
return static::$metaImg ?: 'https://lbry.io/img/lbry-dark-1600x528.png';
}
public static function parseMarkdown($template)
{
$path = static::getFullPath($template);

View file

@ -1,4 +1,5 @@
<?php Response::setMetaDescription($post->getTitle()) ?>
<?php Response::addMetaImages($post->getImageUrls()) ?>
<?php NavActions::setNavUri('/news') ?>
<?php echo View::render('nav/header') ?>
<main>

View file

@ -42,9 +42,12 @@
<!-- Open Graph data -->
<meta property="og:title" content="<?php echo $title ?>" />
<meta property="og:type" content="article" />
<meta property="og:image" content="<?php echo Response::getMetaImage() ?>" />
<meta property="og:description" content="<?php echo Response::getMetaDescription() ?>"/>
<meta property="og:site_name" content="LBRY" />
<?php foreach(Response::getMetaImages() as $image): ?>
<meta property="og:image" content="<?php echo $image ?>" />
<?php endforeach ?>
<base target="_parent" />
</head>

View file

@ -1,5 +1,5 @@
<?php NavActions::setNavUri('/learn') ?>
<?php Response::setMetaImage('https://lbry.io/img/cover-team.jpg') ?>
<?php Response::addMetaImage('https://lbry.io/img/cover-team.jpg') ?>
<?php Response::setMetaDescription('LBRY is founded by a team passionate about connecting producers and consumers and breaking down broken models. Learn more about them.') ?>
<?php echo View::render('nav/header', ['isDark' => false]) ?>
<main>

View file

@ -1,5 +1,5 @@
<?php NavActions::setNavUri('/learn') ?>
<?php Response::setMetaImage('https://lbry.io/img/xkcd-comic.png') ?>
<?php Response::addMetaImage('https://lbry.io/img/xkcd-comic.png') ?>
<?php Response::setMetaDescription('Learn about the inspiration behind LBRY\'s revolutionary content distribution system.') ?>
<?php echo View::render('nav/header', ['isDark' => false]) ?>
<main>