meta image for blog post covers

This commit is contained in:
Jeremy Kauffman 2016-07-15 13:32:10 -04:00
parent 8f8948c6ce
commit cbccfa6e74
2 changed files with 17 additions and 3 deletions

View file

@ -244,9 +244,23 @@ class Post
public function getImageUrls() public function getImageUrls()
{ {
$urls = [];
$cover = $this->getCover();
if ($cover)
{
$urls[] = 'https://' . $_SERVER['SERVER_NAME'] . '/img/' . $cover;
}
$matches = []; $matches = [];
preg_match_all('/!\[.*?\]\((.*?)\)/', $this->markdown, $matches); preg_match_all('/!\[.*?\]\((.*?)\)/', $this->markdown, $matches);
return $matches ? $matches[1] : [];
if ($matches)
{
$urls = array_merge($urls, $matches[1]);
}
return $urls;
} }
protected function markdownToText($markdown) protected function markdownToText($markdown)

View file

@ -17,7 +17,7 @@
</div> </div>
</div> </div>
</header> </header>
<section class="post-content"> <section class="post-content">
<div class="content"> <div class="content">
<?php echo $post->getContentHtml() ?> <?php echo $post->getContentHtml() ?>
@ -30,6 +30,6 @@
<?php if ($post->hasAuthor()): ?> <?php if ($post->hasAuthor()): ?>
<?php echo View::render('content/_postAuthor', ['post' => $post]) ?> <?php echo View::render('content/_postAuthor', ['post' => $post]) ?>
<?php endif ?> <?php endif ?>
</main> </main>
<?php echo View::render('nav/_footer') ?> <?php echo View::render('nav/_footer') ?>