This commit is contained in:
Alex Grintsvayg 2016-09-07 11:17:38 -04:00
parent da47484f70
commit 24e34a032b
5 changed files with 45 additions and 4 deletions

View file

@ -122,6 +122,7 @@ class Controller
$router->get([ContentActions::URL_NEWS . '/{slug:c}?', 'news'], 'ContentActions::executeNews'); $router->get([ContentActions::URL_NEWS . '/{slug:c}?', 'news'], 'ContentActions::executeNews');
$router->get([ContentActions::URL_FAQ . '/{slug:c}?', 'faq'], 'ContentActions::executeFaq'); $router->get([ContentActions::URL_FAQ . '/{slug:c}?', 'faq'], 'ContentActions::executeFaq');
$router->get([BountyActions::URL_BOUNTY . '/{slug:c}?', 'bounty'], 'BountyActions::executeList'); $router->get([BountyActions::URL_BOUNTY . '/{slug:c}?', 'bounty'], 'BountyActions::executeList');
$router->get([ContentActions::URL_PRESS . '/{slug:c}', 'press'], 'ContentActions::executePress');
$router->any(['/signup{whatever}?', 'signup'], 'DownloadActions::executeSignup'); $router->any(['/signup{whatever}?', 'signup'], 'DownloadActions::executeSignup');

View file

@ -6,12 +6,15 @@ class ContentActions extends Actions
SLUG_RSS = 'rss.xml', SLUG_RSS = 'rss.xml',
SLUG_NEWS = 'news', SLUG_NEWS = 'news',
SLUG_FAQ = 'faq', SLUG_FAQ = 'faq',
SLUG_PRESS = 'press',
URL_NEWS = '/' . self::SLUG_NEWS, URL_NEWS = '/' . self::SLUG_NEWS,
URL_FAQ = '/' . self::SLUG_FAQ, URL_FAQ = '/' . self::SLUG_FAQ,
URL_PRESS = '/' . self::SLUG_PRESS,
VIEW_FOLDER_NEWS = ROOT_DIR . '/posts/' . self::SLUG_NEWS, VIEW_FOLDER_NEWS = ROOT_DIR . '/posts/' . self::SLUG_NEWS,
VIEW_FOLDER_FAQ = ROOT_DIR . '/posts/' . self::SLUG_FAQ; VIEW_FOLDER_FAQ = ROOT_DIR . '/posts/' . self::SLUG_FAQ,
VIEW_FOLDER_PRESS = ROOT_DIR . '/posts/' . self::SLUG_PRESS;
public static function executeHome(): array public static function executeHome(): array
{ {
@ -113,7 +116,21 @@ class ContentActions extends Actions
{ {
return NavActions::execute404(); return NavActions::execute404();
} }
return ['content/faq-post', ['post' => $post,]]; return ['content/faq-post', ['post' => $post]];
}
public static function executePress(string $slug = null): array
{
Response::enableHttpCache();
try
{
$post = Post::load(static::SLUG_PRESS . '/' . ltrim($slug, '/'));
}
catch (PostNotFoundException $e)
{
return NavActions::execute404();
}
return ['content/press-post', ['post' => $post]];
} }
public static function executePressKit(): array public static function executePressKit(): array

View file

@ -2,6 +2,8 @@
class PostNotFoundException extends Exception {} class PostNotFoundException extends Exception {}
class PostMalformedException extends Exception {}
class Post class Post
{ {
const SORT_DATE_DESC = 'sort_date_desc'; const SORT_DATE_DESC = 'sort_date_desc';
@ -38,7 +40,11 @@ class Post
throw new PostNotFoundException('No post found for path: ' . $relativeOrAbsolutePath); throw new PostNotFoundException('No post found for path: ' . $relativeOrAbsolutePath);
} }
list($ignored, $frontMatter, $content) = explode('---', file_get_contents($path), 3); list($ignored, $frontMatter, $content) = explode('---', file_get_contents($path), 3) + ['','',''];
if (!$frontMatter || !$content)
{
throw new PostMalformedException('Post "' . basename($path) . '" is missing front matter or content');
}
return new static($postType, $slug, Spyc::YAMLLoadString(trim($frontMatter)), trim($content)); return new static($postType, $slug, Spyc::YAMLLoadString(trim($frontMatter)), trim($content));
} }

5
posts/press/testing.md Normal file
View file

@ -0,0 +1,5 @@
---
title: Press Release
---
stuff goes here

View file

@ -0,0 +1,12 @@
<?php Response::setMetaDescription($post->getTitle()) ?>
<?php Response::addMetaImages($post->getImageUrls()) ?>
<?php echo View::render('nav/_header') ?>
<main>
<section class="post-content">
<div class="content">
<h1><?php echo htmlentities($post->getTitle()) ?></h1>
<?php echo $post->getContentHtml() ?>
</div>
</section>
</main>
<?php echo View::render('nav/_footer') ?>