mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
multiple meta images for posts
This commit is contained in:
parent
f019ccaa1f
commit
a31fb27387
7 changed files with 27 additions and 31 deletions
|
@ -236,6 +236,13 @@ class Post
|
||||||
return $this->getPostNum() % $maxStyles + 1;
|
return $this->getPostNum() % $maxStyles + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getImageUrls()
|
||||||
|
{
|
||||||
|
$matches = [];
|
||||||
|
preg_match_all('/!\[.*?\]\((.*?)\)/', $this->markdown, $matches);
|
||||||
|
return $matches ? $matches[1] : [];
|
||||||
|
}
|
||||||
|
|
||||||
protected function markdownToText($markdown)
|
protected function markdownToText($markdown)
|
||||||
{
|
{
|
||||||
$replacements = [
|
$replacements = [
|
||||||
|
|
|
@ -17,16 +17,24 @@ class Response
|
||||||
'css' => []
|
'css' => []
|
||||||
],
|
],
|
||||||
// $bodyCssClasses = [],
|
// $bodyCssClasses = [],
|
||||||
$metaImg = '';
|
$metaImages = [];
|
||||||
|
|
||||||
public static function setMetaDescription($description)
|
public static function setMetaDescription($description)
|
||||||
{
|
{
|
||||||
static::$metaDescription = $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()
|
public static function getMetaDescription()
|
||||||
|
@ -34,9 +42,9 @@ class Response
|
||||||
return static::$metaDescription ?: 'A Content Revolution';
|
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)
|
public static function setMetaTitle($title)
|
||||||
|
|
|
@ -14,9 +14,6 @@ class View
|
||||||
{
|
{
|
||||||
const LAYOUT_PARAMS = '_layout_params';
|
const LAYOUT_PARAMS = '_layout_params';
|
||||||
|
|
||||||
protected static $metaDescription = '',
|
|
||||||
$metaImg = '';
|
|
||||||
|
|
||||||
public static function render($template, array $vars = [])
|
public static function render($template, array $vars = [])
|
||||||
{
|
{
|
||||||
if (static::isMarkdown($template))
|
if (static::isMarkdown($template))
|
||||||
|
@ -92,26 +89,6 @@ class View
|
||||||
return '/img/' . $image;
|
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)
|
public static function parseMarkdown($template)
|
||||||
{
|
{
|
||||||
$path = static::getFullPath($template);
|
$path = static::getFullPath($template);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php Response::setMetaDescription($post->getTitle()) ?>
|
<?php Response::setMetaDescription($post->getTitle()) ?>
|
||||||
|
<?php Response::addMetaImages($post->getImageUrls()) ?>
|
||||||
<?php NavActions::setNavUri('/news') ?>
|
<?php NavActions::setNavUri('/news') ?>
|
||||||
<?php echo View::render('nav/header') ?>
|
<?php echo View::render('nav/header') ?>
|
||||||
<main>
|
<main>
|
||||||
|
|
|
@ -42,9 +42,12 @@
|
||||||
<!-- Open Graph data -->
|
<!-- Open Graph data -->
|
||||||
<meta property="og:title" content="<?php echo $title ?>" />
|
<meta property="og:title" content="<?php echo $title ?>" />
|
||||||
<meta property="og:type" content="article" />
|
<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:description" content="<?php echo Response::getMetaDescription() ?>"/>
|
||||||
<meta property="og:site_name" content="LBRY" />
|
<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" />
|
<base target="_parent" />
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php NavActions::setNavUri('/learn') ?>
|
<?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 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]) ?>
|
<?php echo View::render('nav/header', ['isDark' => false]) ?>
|
||||||
<main>
|
<main>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php NavActions::setNavUri('/learn') ?>
|
<?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 Response::setMetaDescription('Learn about the inspiration behind LBRY\'s revolutionary content distribution system.') ?>
|
||||||
<?php echo View::render('nav/header', ['isDark' => false]) ?>
|
<?php echo View::render('nav/header', ['isDark' => false]) ?>
|
||||||
<main>
|
<main>
|
||||||
|
|
Loading…
Add table
Reference in a new issue