Skip to content

Commit 97e8eb1

Browse files
authored
Merge pull request #175 from dotkernel/develop
Develop
2 parents f634b96 + ff440b4 commit 97e8eb1

33 files changed

Lines changed: 790 additions & 138 deletions

‎public/robots.txt.dist‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ Disallow: /
77
# To be used in PRODUCTION
88
User-Agent: *
99
Allow: /
10+
11+
Content-Signal: ai-train=yes, search=yes, ai-input=yes
12+
Sitemap: https://www.dotkernel.com/sitemap.xml

‎src/App/src/Factory/GetIndexViewHandlerFactory.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public function __invoke(ContainerInterface $container, string $requestedName):
2626
$template = $container->get(TemplateRendererInterface::class);
2727
assert($template instanceof TemplateRendererInterface);
2828

29-
return new GetIndexViewHandler($template, $postRepository);
29+
$config = $container->get('config');
30+
31+
return new GetIndexViewHandler($template, $postRepository, $config['llms']['pagesDir']);
3032
}
3133
}

‎src/App/src/Factory/GetMarkdownArticleHandlerFactory.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Psr\Container\NotFoundExceptionInterface;
1313

1414
use function assert;
15-
use function getcwd;
1615

1716
class GetMarkdownArticleHandlerFactory
1817
{
@@ -28,6 +27,8 @@ public function __invoke(ContainerInterface $container, string $requestedName):
2827
$categoryRepository = $container->get(CategoryRepository::class);
2928
assert($categoryRepository instanceof CategoryRepository);
3029

31-
return new GetMarkdownArticleHandler($template, $categoryRepository, getcwd() . '/public/md-articles');
30+
$config = $container->get('config');
31+
32+
return new GetMarkdownArticleHandler($template, $categoryRepository, $config['llms']['sourceDir']);
3233
}
3334
}

‎src/App/src/Handler/GetIndexViewHandler.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,41 @@
44

55
namespace Light\App\Handler;
66

7+
use Fig\Http\Message\StatusCodeInterface;
78
use Laminas\Diactoros\Response\HtmlResponse;
9+
use Laminas\Diactoros\Response\TextResponse;
810
use Light\Blog\Repository\PostRepository;
911
use Mezzio\Template\TemplateRendererInterface;
1012
use Psr\Http\Message\ResponseInterface;
1113
use Psr\Http\Message\ServerRequestInterface;
1214
use Psr\Http\Server\RequestHandlerInterface;
1315

16+
use function file_get_contents;
17+
use function is_file;
18+
use function str_contains;
19+
1420
class GetIndexViewHandler implements RequestHandlerInterface
1521
{
1622
public function __construct(
1723
protected TemplateRendererInterface $template,
1824
protected PostRepository $postRepository,
25+
protected string $mdPagesPath,
1926
) {
2027
}
2128

2229
public function handle(ServerRequestInterface $request): ResponseInterface
2330
{
31+
if (str_contains($request->getHeaderLine('Accept'), 'text/markdown')) {
32+
$markdownFile = $this->mdPagesPath . '/index.md';
33+
if (is_file($markdownFile)) {
34+
return new TextResponse(
35+
(string) file_get_contents($markdownFile),
36+
StatusCodeInterface::STATUS_OK,
37+
['Content-Type' => 'text/markdown; charset=utf-8'],
38+
);
39+
}
40+
}
41+
2442
$posts = $this->postRepository->getRecentPosts(3);
2543
return new HtmlResponse(
2644
$this->template->render('app::index', ['posts' => $posts])

‎src/App/templates/layout/default.html.twig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<link rel="icon" type="image/png" sizes="32x32" href="{{ asset('images/app/favicon/favicon-32x32.png') }}">
1515
<link rel="icon" type="image/png" sizes="16x16" href="{{ asset('images/app/favicon/favicon-16x16.png') }}">
1616
<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="{{ url('app::feed') }}" />
17+
<link rel="alternate" type="text/plain" title="llms.txt" href="/llms.txt" />
18+
<link rel="alternate" type="text/plain" title="llms-full.txt" href="/llms-full.txt" />
1719
{% block head_links %}{% endblock %}
1820

1921
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet" />

‎src/Blog/src/ConfigProvider.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Light\Blog\Factory\Author\AuthorCollectionHandlerFactory;
1010
use Light\Blog\Factory\Author\AuthorResourceHandlerFactory;
1111
use Light\Blog\Factory\Author\AuthorResourceRepositoryFactory;
12+
use Light\Blog\Factory\BlogServiceFactory;
1213
use Light\Blog\Factory\Category\CategoryCollectionHandlerFactory;
1314
use Light\Blog\Factory\Category\CategoryCollectionRepositoryFactory;
1415
use Light\Blog\Factory\Category\CategoryResourceHandlerFactory;
@@ -28,6 +29,8 @@
2829
use Light\Blog\Repository\CategoryRepository;
2930
use Light\Blog\Repository\PostRepository;
3031
use Light\Blog\Repository\TagRepository;
32+
use Light\Blog\Service\BlogService;
33+
use Light\Blog\Service\BlogServiceInterface;
3134
use Mezzio\Application;
3235

3336
class ConfigProvider
@@ -51,6 +54,7 @@ public function __invoke(): array
5154
* @return array{
5255
* delegators: array<class-string, array<class-string>>,
5356
* factories: array<class-string, class-string>,
57+
* aliases: array<class-string, class-string>,
5458
* }
5559
*/
5660
private function getDependencies(): array
@@ -73,6 +77,10 @@ private function getDependencies(): array
7377
GetAuthorCollectionHandler::class => AuthorCollectionHandlerFactory::class,
7478
TagRepository::class => TagResourceRepositoryFactory::class,
7579
GetTagResourceHandler::class => TagResourceHandlerFactory::class,
80+
BlogService::class => BlogServiceFactory::class,
81+
],
82+
'aliases' => [
83+
BlogServiceInterface::class => BlogService::class,
7684
],
7785
];
7886
}

‎src/Blog/src/Factory/Author/AuthorResourceHandlerFactory.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Light\Blog\Repository\AuthorRepository;
99
use Light\Blog\Repository\CategoryRepository;
1010
use Light\Blog\Repository\PostRepository;
11+
use Light\Blog\Service\BlogServiceInterface;
1112
use Mezzio\Template\TemplateRendererInterface;
1213
use Psr\Container\ContainerExceptionInterface;
1314
use Psr\Container\ContainerInterface;
@@ -27,11 +28,13 @@ public function __invoke(ContainerInterface $container, string $requestedName):
2728
$template = $container->get(TemplateRendererInterface::class);
2829
$postRepository = $container->get(PostRepository::class);
2930
$categoryRepository = $container->get(CategoryRepository::class);
31+
$blogService = $container->get(BlogServiceInterface::class);
3032

3133
assert($repository instanceof AuthorRepository);
3234
assert($template instanceof TemplateRendererInterface);
3335
assert($postRepository instanceof PostRepository);
36+
assert($blogService instanceof BlogServiceInterface);
3437

35-
return new GetAuthorResourceHandler($template, $repository, $postRepository, $categoryRepository);
38+
return new GetAuthorResourceHandler($template, $repository, $postRepository, $categoryRepository, $blogService);
3639
}
3740
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Light\Blog\Factory;
6+
7+
use Light\Blog\Service\BlogService;
8+
use Light\Blog\Service\BlogServiceInterface;
9+
use Mezzio\Template\TemplateRendererInterface;
10+
use Psr\Container\ContainerExceptionInterface;
11+
use Psr\Container\ContainerInterface;
12+
use Psr\Container\NotFoundExceptionInterface;
13+
14+
use function assert;
15+
16+
class BlogServiceFactory
17+
{
18+
/**
19+
* @throws ContainerExceptionInterface
20+
* @throws NotFoundExceptionInterface
21+
*/
22+
public function __invoke(ContainerInterface $container, string $requestedName): BlogServiceInterface
23+
{
24+
$template = $container->get(TemplateRendererInterface::class);
25+
assert($template instanceof TemplateRendererInterface);
26+
27+
$config = $container->get('config');
28+
29+
return new BlogService($template, $config['llms']['sourceDir']);
30+
}
31+
}

‎src/Blog/src/Factory/Category/CategoryResourceHandlerFactory.php‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Light\Blog\Handler\GetCategoryResourceHandler;
88
use Light\Blog\Repository\CategoryRepository;
9+
use Light\Blog\Service\BlogServiceInterface;
910
use Mezzio\Template\TemplateRendererInterface;
1011
use Psr\Container\ContainerExceptionInterface;
1112
use Psr\Container\ContainerInterface;
@@ -21,12 +22,14 @@ class CategoryResourceHandlerFactory
2122
*/
2223
public function __invoke(ContainerInterface $container, string $requestedName): GetCategoryResourceHandler
2324
{
24-
$repository = $container->get(CategoryRepository::class);
25-
$template = $container->get(TemplateRendererInterface::class);
25+
$repository = $container->get(CategoryRepository::class);
26+
$template = $container->get(TemplateRendererInterface::class);
27+
$blogService = $container->get(BlogServiceInterface::class);
2628

2729
assert($repository instanceof CategoryRepository);
2830
assert($template instanceof TemplateRendererInterface);
31+
assert($blogService instanceof BlogServiceInterface);
2932

30-
return new GetCategoryResourceHandler($template, $repository);
33+
return new GetCategoryResourceHandler($template, $repository, $blogService);
3134
}
3235
}

‎src/Blog/src/Factory/Post/PostResourceHandlerFactory.php‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Light\Blog\Handler\GetPostResourceHandler;
88
use Light\Blog\Repository\CategoryRepository;
99
use Light\Blog\Repository\PostRepository;
10+
use Light\Blog\Service\BlogServiceInterface;
1011
use Mezzio\Template\TemplateRendererInterface;
1112
use Psr\Container\ContainerExceptionInterface;
1213
use Psr\Container\ContainerInterface;
@@ -25,10 +26,17 @@ public function __invoke(ContainerInterface $container, string $requestedName):
2526
$repository = $container->get(PostRepository::class);
2627
$categoryRepository = $container->get(CategoryRepository::class);
2728
$template = $container->get(TemplateRendererInterface::class);
29+
$blogService = $container->get(BlogServiceInterface::class);
2830

2931
assert($repository instanceof PostRepository);
3032
assert($template instanceof TemplateRendererInterface);
33+
assert($blogService instanceof BlogServiceInterface);
3134

32-
return new GetPostResourceHandler($template, $repository, $categoryRepository);
35+
return new GetPostResourceHandler(
36+
$template,
37+
$repository,
38+
$categoryRepository,
39+
$blogService
40+
);
3341
}
3442
}

0 commit comments

Comments
 (0)