mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
53 lines
No EOL
1 KiB
PHP
53 lines
No EOL
1 KiB
PHP
<?php
|
|
|
|
class Blog
|
|
{
|
|
protected static $slugMap = [];
|
|
|
|
public static function getPosts()
|
|
{
|
|
$posts = [];
|
|
foreach(static::getAllPostPaths() as $file)
|
|
{
|
|
$posts[] = Post::fromFile($file);
|
|
}
|
|
return $posts;
|
|
}
|
|
|
|
public static function getPost($slug)
|
|
{
|
|
static::initSlugMap();
|
|
if (isset(static::$slugMap[$slug]) && is_readable(static::$slugMap[$slug]))
|
|
{
|
|
return Post::fromFile(static::$slugMap[$slug]);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static function getSlugFromFilename($filename)
|
|
{
|
|
return strtolower(preg_replace('#^\d+\-#', '', basename(trim($filename), '.md')));
|
|
}
|
|
|
|
protected static function initSlugMap()
|
|
{
|
|
if (!static::$slugMap)
|
|
{
|
|
foreach(static::getAllPostPaths() as $file)
|
|
{
|
|
static::$slugMap[static::getSlugFromFilename($file)] = $file;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected static function getAllPostPaths()
|
|
{
|
|
return glob(ROOT_DIR . '/view/posts/*.md');
|
|
}
|
|
|
|
public static function getSlugMap()
|
|
{
|
|
static::initSlugMap();
|
|
return static::$slugMap;
|
|
}
|
|
} |