Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions public/robots.txt.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ Disallow: /
# To be used in PRODUCTION
User-Agent: *
Allow: /

Content-Signal: ai-train=yes, search=yes, ai-input=yes
Sitemap: https://www.dotkernel.com/sitemap.xml
3 changes: 2 additions & 1 deletion src/App/src/Factory/GetIndexViewHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Psr\Container\NotFoundExceptionInterface;

use function assert;
use function getcwd;

class GetIndexViewHandlerFactory
{
Expand All @@ -26,6 +27,6 @@ public function __invoke(ContainerInterface $container, string $requestedName):
$template = $container->get(TemplateRendererInterface::class);
assert($template instanceof TemplateRendererInterface);

return new GetIndexViewHandler($template, $postRepository);
return new GetIndexViewHandler($template, $postRepository, getcwd() . '/public/md-pages');
}
}
18 changes: 18 additions & 0 deletions src/App/src/Handler/GetIndexViewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,41 @@

namespace Light\App\Handler;

use Fig\Http\Message\StatusCodeInterface;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\Response\TextResponse;
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 function file_get_contents;
use function is_file;
use function str_contains;

class GetIndexViewHandler implements RequestHandlerInterface
{
public function __construct(
protected TemplateRendererInterface $template,
protected PostRepository $postRepository,
protected string $mdPagesPath,
) {
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
if (str_contains($request->getHeaderLine('Accept'), 'text/markdown')) {
$markdownFile = $this->mdPagesPath . '/index.md';
if (is_file($markdownFile)) {
return new TextResponse(
(string) file_get_contents($markdownFile),
StatusCodeInterface::STATUS_OK,
['Content-Type' => 'text/markdown; charset=utf-8'],
);
}
}

$posts = $this->postRepository->getRecentPosts(3);
return new HtmlResponse(
$this->template->render('app::index', ['posts' => $posts])
Expand Down
2 changes: 2 additions & 0 deletions src/App/templates/layout/default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<link rel="icon" type="image/png" sizes="32x32" href="{{ asset('images/app/favicon/favicon-32x32.png') }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ asset('images/app/favicon/favicon-16x16.png') }}">
<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="{{ url('app::feed') }}" />
<link rel="alternate" type="text/plain" title="llms.txt" href="/llms.txt" />
<link rel="alternate" type="text/plain" title="llms-full.txt" href="/llms-full.txt" />
{% block head_links %}{% endblock %}

<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet" />
Expand Down
8 changes: 8 additions & 0 deletions src/Blog/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Light\Blog\Factory\Author\AuthorCollectionHandlerFactory;
use Light\Blog\Factory\Author\AuthorResourceHandlerFactory;
use Light\Blog\Factory\Author\AuthorResourceRepositoryFactory;
use Light\Blog\Factory\BlogServiceFactory;
use Light\Blog\Factory\Category\CategoryCollectionHandlerFactory;
use Light\Blog\Factory\Category\CategoryCollectionRepositoryFactory;
use Light\Blog\Factory\Category\CategoryResourceHandlerFactory;
Expand All @@ -28,6 +29,8 @@
use Light\Blog\Repository\CategoryRepository;
use Light\Blog\Repository\PostRepository;
use Light\Blog\Repository\TagRepository;
use Light\Blog\Service\BlogService;
use Light\Blog\Service\BlogServiceInterface;
use Mezzio\Application;

class ConfigProvider
Expand All @@ -51,6 +54,7 @@ public function __invoke(): array
* @return array{
* delegators: array<class-string, array<class-string>>,
* factories: array<class-string, class-string>,
* aliases: array<class-string, class-string>,
* }
*/
private function getDependencies(): array
Expand All @@ -73,6 +77,10 @@ private function getDependencies(): array
GetAuthorCollectionHandler::class => AuthorCollectionHandlerFactory::class,
TagRepository::class => TagResourceRepositoryFactory::class,
GetTagResourceHandler::class => TagResourceHandlerFactory::class,
BlogService::class => BlogServiceFactory::class,
],
'aliases' => [
BlogServiceInterface::class => BlogService::class,
],
];
}
Expand Down
5 changes: 4 additions & 1 deletion src/Blog/src/Factory/Author/AuthorResourceHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Light\Blog\Repository\AuthorRepository;
use Light\Blog\Repository\CategoryRepository;
use Light\Blog\Repository\PostRepository;
use Light\Blog\Service\BlogServiceInterface;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
Expand All @@ -27,11 +28,13 @@ public function __invoke(ContainerInterface $container, string $requestedName):
$template = $container->get(TemplateRendererInterface::class);
$postRepository = $container->get(PostRepository::class);
$categoryRepository = $container->get(CategoryRepository::class);
$blogService = $container->get(BlogServiceInterface::class);

assert($repository instanceof AuthorRepository);
assert($template instanceof TemplateRendererInterface);
assert($postRepository instanceof PostRepository);
assert($blogService instanceof BlogServiceInterface);

return new GetAuthorResourceHandler($template, $repository, $postRepository, $categoryRepository);
return new GetAuthorResourceHandler($template, $repository, $postRepository, $categoryRepository, $blogService);
}
}
30 changes: 30 additions & 0 deletions src/Blog/src/Factory/BlogServiceFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Light\Blog\Factory;

use Light\Blog\Service\BlogService;
use Light\Blog\Service\BlogServiceInterface;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

use function assert;
use function getcwd;

class BlogServiceFactory
{
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container, string $requestedName): BlogServiceInterface
{
$template = $container->get(TemplateRendererInterface::class);
assert($template instanceof TemplateRendererInterface);

return new BlogService($template, getcwd() . '/public/md-articles');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Light\Blog\Handler\GetCategoryResourceHandler;
use Light\Blog\Repository\CategoryRepository;
use Light\Blog\Service\BlogServiceInterface;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
Expand All @@ -21,12 +22,14 @@ class CategoryResourceHandlerFactory
*/
public function __invoke(ContainerInterface $container, string $requestedName): GetCategoryResourceHandler
{
$repository = $container->get(CategoryRepository::class);
$template = $container->get(TemplateRendererInterface::class);
$repository = $container->get(CategoryRepository::class);
$template = $container->get(TemplateRendererInterface::class);
$blogService = $container->get(BlogServiceInterface::class);

assert($repository instanceof CategoryRepository);
assert($template instanceof TemplateRendererInterface);
assert($blogService instanceof BlogServiceInterface);

return new GetCategoryResourceHandler($template, $repository);
return new GetCategoryResourceHandler($template, $repository, $blogService);
}
}
10 changes: 9 additions & 1 deletion src/Blog/src/Factory/Post/PostResourceHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Light\Blog\Handler\GetPostResourceHandler;
use Light\Blog\Repository\CategoryRepository;
use Light\Blog\Repository\PostRepository;
use Light\Blog\Service\BlogServiceInterface;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
Expand All @@ -25,10 +26,17 @@ public function __invoke(ContainerInterface $container, string $requestedName):
$repository = $container->get(PostRepository::class);
$categoryRepository = $container->get(CategoryRepository::class);
$template = $container->get(TemplateRendererInterface::class);
$blogService = $container->get(BlogServiceInterface::class);

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

return new GetPostResourceHandler($template, $repository, $categoryRepository);
return new GetPostResourceHandler(
$template,
$repository,
$categoryRepository,
$blogService
);
}
}
5 changes: 4 additions & 1 deletion src/Blog/src/Factory/Tag/TagResourceHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Light\Blog\Handler\GetTagResourceHandler;
use Light\Blog\Repository\CategoryRepository;
use Light\Blog\Repository\TagRepository;
use Light\Blog\Service\BlogServiceInterface;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
Expand All @@ -25,11 +26,13 @@ public function __invoke(ContainerInterface $container, string $requestedName):
$repository = $container->get(TagRepository::class);
$template = $container->get(TemplateRendererInterface::class);
$categoryRepository = $container->get(CategoryRepository::class);
$blogService = $container->get(BlogServiceInterface::class);

assert($repository instanceof TagRepository);
assert($template instanceof TemplateRendererInterface);
assert($categoryRepository instanceof CategoryRepository);
assert($blogService instanceof BlogServiceInterface);

return new GetTagResourceHandler($template, $repository, $categoryRepository);
return new GetTagResourceHandler($template, $repository, $categoryRepository, $blogService);
}
}
19 changes: 3 additions & 16 deletions src/Blog/src/Handler/GetAuthorResourceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

namespace Light\Blog\Handler;

use Fig\Http\Message\StatusCodeInterface;
use Laminas\Diactoros\Response\HtmlResponse;
use Light\App\Helper\Paginator;
use Light\Blog\Entity\Author;
use Light\Blog\Repository\AuthorRepository;
use Light\Blog\Repository\CategoryRepository;
use Light\Blog\Repository\PostRepository;
use Light\Blog\Service\BlogServiceInterface;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -23,6 +22,7 @@ public function __construct(
protected AuthorRepository $authorRepository,
protected PostRepository $postRepository,
protected CategoryRepository $categoryRepository,
protected BlogServiceInterface $blogService,
) {
}

Expand All @@ -31,7 +31,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$authorSlug = $request->getAttribute('slug');
$author = $this->authorRepository->getAuthorResource($authorSlug);
if (! $author) {
return $this->notFound($this->authorRepository->getAuthorsWithPublishedPosts());
return $this->blogService->authorNotFound($this->authorRepository->getAuthorsWithPublishedPosts());
}
$categories = $this->categoryRepository->getCategories();

Expand All @@ -51,17 +51,4 @@ public function handle(ServerRequestInterface $request): ResponseInterface
])
);
}

/**
* @param Author[] $authors
*/
private function notFound(array $authors): HtmlResponse
{
return new HtmlResponse(
$this->template->render('error::404', [
'authors' => $authors,
]),
StatusCodeInterface::STATUS_NOT_FOUND
);
}
}
36 changes: 5 additions & 31 deletions src/Blog/src/Handler/GetCategoryResourceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

namespace Light\Blog\Handler;

use Fig\Http\Message\StatusCodeInterface;
use Laminas\Diactoros\Response\HtmlResponse;
use Light\App\Helper\Paginator;
use Light\Blog\Entity\Category;
use Light\Blog\Repository\CategoryRepository;
use Light\Blog\Service\BlogServiceInterface;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -20,6 +19,7 @@ class GetCategoryResourceHandler implements RequestHandlerInterface
public function __construct(
protected TemplateRendererInterface $template,
protected CategoryRepository $categoryRepository,
protected BlogServiceInterface $blogService,
) {
}

Expand All @@ -29,10 +29,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$categories = $this->categoryRepository->getCategories();
$category = $this->categoryRepository->getCategoryResource($categorySlug);
if ($category === null) {
return $this->notFound($categories);
return $this->blogService->notFound($categories);
}
if (! $category->isVisible()) {
return $this->gone($categories);
return $this->blogService->gone($categories);
}
$meta = $category;

Expand All @@ -55,33 +55,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
);
return new HtmlResponse($html);
} catch (Throwable $e) {
return $this->notFound($categories);
return $this->blogService->notFound($categories);
}
}

/**
* @param Category[] $categories
*/
private function notFound(array $categories): HtmlResponse
{
return new HtmlResponse(
$this->template->render('error::404', [
'categories' => $categories,
]),
StatusCodeInterface::STATUS_NOT_FOUND
);
}

/**
* @param Category[] $categories
*/
private function gone(array $categories): HtmlResponse
{
return new HtmlResponse(
$this->template->render('error::410', [
'categories' => $categories,
]),
StatusCodeInterface::STATUS_GONE
);
}
}
Loading