mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
60 lines
No EOL
1.5 KiB
PHP
60 lines
No EOL
1.5 KiB
PHP
<?php
|
|
|
|
class Post
|
|
{
|
|
protected $slug, $title, $author, $date, $contentHtml;
|
|
|
|
public static function fromFile($filename)
|
|
{
|
|
list($ignored, $frontMatter, $content) = explode('---', file_get_contents($filename), 3);
|
|
return new static(Blog::getSlugFromFilename($filename), Spyc::YAMLLoadString(trim($frontMatter)), trim($content));
|
|
}
|
|
|
|
public function __construct($slug, $frontMatter, $markdown)
|
|
{
|
|
$this->slug = $slug;
|
|
$this->title = isset($frontMatter['title']) ? $frontMatter['title'] : null;
|
|
$this->author = isset($frontMatter['author']) ? $frontMatter['author'] : null;
|
|
$this->date = isset($frontMatter['date']) ? new DateTime($frontMatter['date']) : null;
|
|
$this->contentHtml = ParsedownExtra::instance()->text(trim($markdown));
|
|
}
|
|
|
|
public function getSlug()
|
|
{
|
|
return $this->slug;
|
|
}
|
|
|
|
public function getTitle()
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
public function getAuthor()
|
|
{
|
|
return $this->author;
|
|
}
|
|
|
|
public function getDate()
|
|
{
|
|
return $this->date;
|
|
}
|
|
|
|
public function getContentHtml()
|
|
{
|
|
return $this->contentHtml;
|
|
}
|
|
|
|
public function getPrevPostSlug()
|
|
{
|
|
$slugs = array_keys(Blog::getSlugMap());
|
|
$key = array_search($this->getSlug(), $slugs);
|
|
return $key === false || $key === 0 ? null : $slugs[$key-1];
|
|
}
|
|
|
|
public function getNextPostSlug()
|
|
{
|
|
$slugs = array_keys(Blog::getSlugMap());
|
|
$key = array_search($this->getSlug(), $slugs);
|
|
return $key === false || $key >= count($slugs)-1 ? null : $slugs[$key+1];
|
|
}
|
|
} |