Skip to content
Merged
4 changes: 2 additions & 2 deletions src/App/templates/layout/default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<a class="nav-link px-3 fw-semibold fs-5 transition-all" target="_blank" href="https://docs.dotkernel.org/">Documentation</a>
</li>
<li class="nav-item">
<a class="nav-link px-3 fw-semibold fs-5 transition-all" href="{{ url('page::dotkernel-packages-oss-lifecycle') }}">Packages Lifecycle</a>
<a class="nav-link px-3 fw-semibold fs-5 transition-all" href="{{ url('page::static-page', {'static-page': 'dotkernel-packages-oss-lifecycle'}) }}">Packages Lifecycle</a>
Comment thread
alexmerlin marked this conversation as resolved.
Outdated
</li>
<li class="nav-item">
<a class="nav-link px-3 fw-semibold fs-5 transition-all" href="{{ url('page::category-resource', {slug: 'how-to'}) }}">How to's</a>
Expand All @@ -47,7 +47,7 @@
</li>
</ul>
<div class="d-none d-lg-block">
<a href="{{ url('page::contact') }}" class="btn btn-primary rounded-pill px-4">Contact</a>
<a href="{{ url('page::static-page', {'static-page': 'contact'}) }}" class="btn btn-primary rounded-pill px-4">Contact</a>
Comment thread
alexmerlin marked this conversation as resolved.
Outdated
</div>
</div>
</div>
Expand Down
28 changes: 25 additions & 3 deletions src/App/templates/partial/left-menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
class="list-group-item list-group-item-action border-0 px-1 py-2 rounded">
<p class="mb-1 small fw-semibold text-dark lh-sm">{{ article.title }}</p>
<span class="text-muted" >
<i class="bi bi-calendar3 me-1"></i>{{ article.postDate|date('M d, Y') }}
</span>
<i class="bi bi-calendar3 me-1"></i>{{ article.postDate|date('M d, Y') }}
</span>
</a>
{% else %}
<p class="text-muted small mb-0">No recent articles.</p>
Expand Down Expand Up @@ -52,9 +52,31 @@
See all categories <i class="bi bi-arrow-right fs-7"></i>
</a>
</div>
</div>
</div>
{% if posts is defined and posts %}
Comment thread
alexmerlin marked this conversation as resolved.
Outdated
<div class="card border-0 shadow-sm rounded-3 my-2">
<div class="card-body p-3">
<h6 class="fw-bold text-uppercase text-muted small px-1 mb-2">Recent Articles</h6>

<div class="list-group list-group-flush">

{% for post in posts %}
<a href="{{ url('page::blog-resource', {categorySlug: post.category.slug, slug: post.slug}) }}"
class="list-group-item list-group-item-action border-0 px-1 py-2 rounded">
<p class="mb-1 small fw-semibold text-dark lh-sm">{{ post.title }}</p>
<span class="text-muted">
<i class="bi bi-calendar3 me-1"></i>{{ post.postDate|date('M d, Y') }}
</span>
</a>
{% else %}
<p class="text-muted small mb-0">No recent articles.</p>
{% endfor %}

</div>
</div>
</div>
{% endif %}

</div>
</div>
</aside>
3 changes: 3 additions & 0 deletions src/Blog/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
use Light\Blog\Factory\Post\PostCollectionHandlerFactory;
use Light\Blog\Factory\Post\PostCollectionRepositoryFactory;
use Light\Blog\Factory\Post\PostResourceHandlerFactory;
use Light\Blog\Factory\StaticPages\GetStaticPageDataFactory;
use Light\Blog\Handler\GetAuthorResourceHandler;
use Light\Blog\Handler\GetCategoryCollectionHandler;
use Light\Blog\Handler\GetCategoryResourceHandler;
use Light\Blog\Handler\GetPostCollectionHandler;
use Light\Blog\Handler\GetPostResourceHandler;
use Light\Blog\Handler\GetStaticPageDataHandler;
use Light\Blog\Repository\AuthorRepository;
use Light\Blog\Repository\CategoryRepository;
use Light\Blog\Repository\PostRepository;
Expand Down Expand Up @@ -64,6 +66,7 @@ private function getDependencies(): array
GetCategoryResourceHandler::class => CategoryResourceHandlerFactory::class,
AuthorRepository::class => AuthorResourceRepositoryFactory::class,
GetAuthorResourceHandler::class => AuthorResourceHandlerFactory::class,
GetStaticPageDataHandler::class => GetStaticPageDataFactory::class,
],
];
}
Expand Down
34 changes: 34 additions & 0 deletions src/Blog/src/Factory/StaticPages/GetStaticPageDataFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Light\Blog\Factory\StaticPages;

use Light\Blog\Handler\GetStaticPageDataHandler;
use Light\Blog\Repository\CategoryRepository;
use Light\Blog\Repository\PostRepository;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

use function assert;

class GetStaticPageDataFactory
{
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container, string $requestedName): GetStaticPageDataHandler
{
$repository = $container->get(PostRepository::class);
$categoryRepository = $container->get(CategoryRepository::class);
$template = $container->get(TemplateRendererInterface::class);

assert($repository instanceof PostRepository);
assert($template instanceof TemplateRendererInterface);

return new GetStaticPageDataHandler($template, $repository, $categoryRepository);
}
}
55 changes: 55 additions & 0 deletions src/Blog/src/Handler/GetStaticPageDataHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Light\Blog\Handler;

use Laminas\Diactoros\Response\HtmlResponse;
use Light\Blog\Repository\CategoryRepository;
use Light\Blog\Repository\PostRepository;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Throwable;

class GetStaticPageDataHandler implements RequestHandlerInterface
{
public function __construct(
protected TemplateRendererInterface $template,
protected PostRepository $articleRepository,
protected CategoryRepository $categoryRepository,
) {
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
$staticPage = $request->getAttribute('static-page');

$posts = $this->articleRepository->getRecentPosts(3);
$categories = $this->categoryRepository->getCategories();

try {
$html = $this->template->render('page::' . $staticPage, [
'categories' => $categories,
'posts' => $posts,
]);
} catch (Throwable $e) {
return $this->notFound();
Comment thread
alexmerlin marked this conversation as resolved.
Outdated
}

return new HtmlResponse($html);
}

private function notFound(): HtmlResponse
{
$categories = $this->categoryRepository->getCategories();

return new HtmlResponse(
$this->template->render('error::404', [
'categories' => $categories,
]),
404
Comment thread
alexmerlin marked this conversation as resolved.
Outdated
);
}
}
16 changes: 16 additions & 0 deletions src/Blog/src/Repository/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,20 @@ public function getArticleByAuthor(Author $author, array $params): DoctrinePagin

return new DoctrinePaginator($qb->getQuery());
}

/**
* @return array<int, Post>
*/
public function getRecentPosts(int $limit = 5): array
{
$qb = $this->getQueryBuilder()
->select('articles')
->from(Post::class, 'articles')
->where('articles.status = :published')
->setParameter('published', PostStatusEnum::Published)
->orderBy('articles.postDate', 'DESC')
->setMaxResults($limit);

return $qb->getQuery()->getResult();
}
}
3 changes: 3 additions & 0 deletions src/Blog/src/RoutesDelegator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Light\Blog\Handler\GetCategoryResourceHandler;
use Light\Blog\Handler\GetPostCollectionHandler;
use Light\Blog\Handler\GetPostResourceHandler;
use Light\Blog\Handler\GetStaticPageDataHandler;
use Mezzio\Application;
use Psr\Container\ContainerInterface;

Expand All @@ -25,6 +26,8 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal
$app->get('/categories/', [GetCategoryCollectionHandler::class], 'page::categories');
$app->get('/author/{slug}/', [GetAuthorResourceHandler::class], 'page::author-resource');
$app->get('/{categorySlug}/{slug}/', [GetPostResourceHandler::class], 'page::blog-resource');

$app->get('/{static-page}/', [GetStaticPageDataHandler::class], 'page::static-page');
Comment thread
alexmerlin marked this conversation as resolved.
Outdated
return $app;
}
}
41 changes: 0 additions & 41 deletions src/Blog/templates/page/category-resource/architecture.html.twig

This file was deleted.

41 changes: 0 additions & 41 deletions src/Blog/templates/page/category-resource/default.html.twig

This file was deleted.

41 changes: 0 additions & 41 deletions src/Blog/templates/page/category-resource/dotkernel.html.twig

This file was deleted.

Loading