/**
* List all of the blog posts for a given year
*
* @route blog/category/{slug}/{page}
* @param string $slug
* @param string $page
* @throws EmulatePageNotFound
*/
public function listByCategory(string $slug = '', string $page = '')
{
list($offset, $limit) = $this->getOffsetAndLimit($page);
if (!empty($slug)) {
$category = $this->blog->getCategory($slug);
if (empty($category)) {
throw new EmulatePageNotFound();
}
$cats = $this->blog->expandCategory($category['categoryid']);
if (!\in_array($category['categoryid'], $cats)) {
\array_unshift($cats, $category['categoryid']);
}
} else {
$category = ['name' => 'Uncategorized'];
$cats = [];
}
$count = $this->blog->countByCategories($cats);
$blogRoll = $this->blog->listByCategories($cats, $limit, $offset);
$mathJAX = false;
foreach ($blogRoll as $i => $blog) {
$blogRoll[$i] = $this->blog->getSnippet($blog);
if (Binary::safeStrlen($blogRoll[$i]['snippet']) !== Binary::safeStrlen($blog['body'])) {
$blogRoll[$i]['snippet'] = \rtrim($blogRoll[$i]['snippet'], "\n");
}
$mathJAX = $mathJAX || \strpos($blog['body'], '$$') !== false;
}
$args = ['category' => $category, 'blogroll' => $blogRoll, 'mathjax' => $mathJAX, 'pagination' => ['base' => \Airship\LensFunctions\cabin_url() . 'blog/category/' . $slug, 'count' => $count, 'page' => (int) \ceil($offset / ($limit ?? 1)) + 1, 'per_page' => $limit]];
$this->config('blog.cachelists') ? $this->stasis('blog/category', $args) : $this->lens('blog/category', $args);
}