-
Notifications
You must be signed in to change notification settings - Fork 0
Static pages #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Static pages #9
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5375aea
Static pages
OStefan2001 5521cac
Use GetPageViewHandler for static pages. Update routes and unit tests
OStefan2001 dc53f53
cs-fix
OStefan2001 01a2cf0
Remove database fetch duplication and frontpage updates. Updated loca…
OStefan2001 af8c39a
Conditional rendering of recent posts section
OStefan2001 1a3e607
Img path fix, local.php.dist update, and applied recommendations for …
OStefan2001 f5c0cca
Img path fix
OStefan2001 b43f509
Add missing icons and update SVG paths
OStefan2001 65d2395
Add missing icons and update SVG paths
OStefan2001 05be1f8
add images in app/src
OStefan2001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/Blog/src/Factory/StaticPages/GetStaticPageDataFactory.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
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 | ||
|
alexmerlin marked this conversation as resolved.
Outdated
|
||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
src/Blog/templates/page/category-resource/architecture.html.twig
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
src/Blog/templates/page/category-resource/default.html.twig
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
src/Blog/templates/page/category-resource/dotkernel.html.twig
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.