Skip to content

Commit 0c47803

Browse files
smnandrekbond
authored andcommitted
[Site] Clean cook
1 parent b066280 commit 0c47803

File tree

17 files changed

+190
-204
lines changed

17 files changed

+190
-204
lines changed
Loading
Loading
Binary file not shown.
Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,15 @@
11
.Cookbook {
2-
h1 {
3-
margin-top: 3rem;
4-
margin-bottom: 1rem;
5-
text-align: center;
6-
font-size: 52px;
7-
font-weight: 700;
8-
line-height: 60px;
9-
}
10-
11-
.description {
12-
text-align: center;
13-
font-size: 24px;
14-
font-weight: 600;
15-
margin-top: 1.5rem;
16-
}
17-
18-
.tags {
19-
display: flex;
20-
justify-content: center;
21-
align-items: center;
22-
width: 100%;
23-
gap: 1rem;
24-
text-decoration: none;
25-
list-style: none;
26-
margin-bottom: 3rem;
27-
28-
li {
29-
background-color: rgb(74 29 150);
30-
color: rgb(202 191 253);
31-
font-weight: 500;
32-
font-size: 0.75rem;
33-
line-height: 1rem;
34-
padding: .125rem .625rem;
35-
border-radius: 0.25rem;
36-
}
37-
}
382

393
.image-title {
40-
width: 100%;
41-
max-height: 40vh;
424
overflow: hidden;
43-
border-radius: 4px;
44-
margin-bottom: 3rem;
5+
width: auto;
6+
border-radius: .75rem;
7+
aspect-ratio: 16 / 9;
8+
max-width: 1280px;
459

4610
img {
4711
display: block;
48-
object-fit: contain;
12+
object-fit: cover;
4913
width: 100%;
5014
}
5115
}
@@ -65,15 +29,22 @@
6529
font-size: 24px;
6630
font-weight: 700;
6731
line-height: 32px;
68-
color: #FFFFFF;
32+
color: var(--color-text);
33+
}
34+
35+
h4 {
36+
margin-top: 3rem;
37+
margin-bottom: 1rem;
6938
}
7039
}
7140

7241
pre {
73-
margin-top: 4rem;
74-
margin-bottom: 2rem;
75-
border-radius: 4px;
42+
margin-block: 2rem;
43+
border-radius: .75rem;
7644
background-color: #0A0A0A;
77-
padding: 2rem;
45+
padding: 1rem 1.5rem;
46+
color: #d7e2e3;
47+
font-size: 1rem;
48+
line-height: 1.5;
7849
}
79-
}
50+
}

ux.symfony.com/assets/styles/components/_DemoCard.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
box-shadow: 0 0 0 transparent;
1818
background: var(--bs-body-bg);
1919
}
20+
2021
.DemoCard:hover {
2122
transition: color 250ms ease-in-out, transform 250ms ease-in-out, box-shadow 250ms ease-in-out;
2223
transform: translateY(-.25rem);
@@ -36,11 +37,12 @@
3637
}
3738

3839
.DemoCard__image {
39-
max-height: 100%;
40-
width: 100%;
40+
max-width: 100%;
4141
display: block;
42+
object-fit: cover;
4243
opacity: .90;
4344
}
45+
4446
.DemoCard:hover .DemoCard__image {
4547
opacity: .93;
4648
}
@@ -71,6 +73,7 @@
7173
line-height: 1.4;
7274
margin: 0;
7375
}
76+
7477
.DemoCard:hover .DemoCard__description {
7578
opacity: .85;
7679
}
@@ -80,5 +83,5 @@
8083
margin-bottom: 0;
8184
display: flex;
8285
flex-wrap: wrap;
83-
gap: .5rem;
86+
gap: .5rem;
8487
}

ux.symfony.com/config/packages/twig.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ twig:
44

55
paths:
66
'%kernel.project_dir%/templates/demos/live_memory': ~
7+
'%kernel.project_dir%/cookbook/': 'Cookbook'
78

89
when@test:
910
twig:

ux.symfony.com/config/services.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ services:
1010
_defaults:
1111
autowire: true # Automatically injects dependencies in your services.
1212
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
13-
bind:
14-
string $cookbookPath: '%kernel.project_dir%/cookbook'
1513

1614
# makes classes in src/ available to be used as services
1715
# this creates a service per class whose id is the fully-qualified class name

ux.symfony.com/cookbook/architecture_component.md renamed to ux.symfony.com/cookbook/component_architecture.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Architecture component
2+
title: Component architecture
33
description: Rules and pattern to work with components
4-
image: images/cookbook/component_architecture.png
4+
image: images/cookbook/component-architecture.png
55
tags:
66
- javascript
77
- symfony
@@ -174,5 +174,5 @@ class Button
174174
## Conclusion
175175

176176
Even in Symfony, you can use the component architecture.
177-
Follow those rules help your front developpers working on codebase
178-
their are familiar with since those rules are already used in the js world.
177+
Follow those rules help your front developers working on codebase
178+
they are familiar with since those rules are already used in the JS world.

ux.symfony.com/src/Controller/CookbookController.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@
1111

1212
namespace App\Controller;
1313

14-
use App\Service\CookbookFactory;
1514
use App\Service\CookbookRepository;
1615
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1716
use Symfony\Component\HttpFoundation\Response;
1817
use Symfony\Component\Routing\Attribute\Route;
18+
use Symfony\Component\Routing\Requirement\Requirement;
1919

2020
class CookbookController extends AbstractController
2121
{
2222
public function __construct(
23-
private CookbookRepository $cookbookRepository,
24-
private CookbookFactory $cookbookFactory,
23+
private readonly CookbookRepository $cookbookRepository,
2524
) {
2625
}
2726

28-
#[Route('/cookbook', name: 'app_cookbook_index')]
27+
#[Route('/cookbook', name: 'app_cookbook')]
2928
public function index(): Response
3029
{
3130
$cookbooks = $this->cookbookRepository->findAll();
@@ -35,13 +34,15 @@ public function index(): Response
3534
]);
3635
}
3736

38-
#[Route('/cookbook/{slug}', name: 'app_cookbook_show')]
37+
#[Route('/cookbook/{slug}', name: 'app_cookbook_show', requirements: ['slug' => Requirement::ASCII_SLUG])]
3938
public function show(string $slug): Response
4039
{
41-
$cookbook = $this->cookbookRepository->findOneByName($slug);
40+
$cookbook = $this->cookbookRepository->findOneBySlug($slug);
41+
if (!$cookbook) {
42+
throw $this->createNotFoundException(\sprintf('Cookbook "%s" not found', $slug));
43+
}
4244

4345
return $this->render('cookbook/show.html.twig', [
44-
'slug' => $slug,
4546
'cookbook' => $cookbook,
4647
]);
4748
}

ux.symfony.com/src/Model/Cookbook.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111

1212
namespace App\Model;
1313

14-
class Cookbook
14+
final readonly class Cookbook
1515
{
16+
/**
17+
* @param list<string> $tags
18+
*/
1619
public function __construct(
1720
public string $title,
18-
public string $description,
19-
public string $route,
21+
public string $slug,
2022
public string $image,
23+
public string $description,
2124
public string $content,
22-
/**
23-
* @var string[]
24-
*/
25-
public array $tags = [],
25+
public array $tags,
2626
) {
2727
}
2828
}

ux.symfony.com/src/Service/CookbookFactory.php

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,51 @@
1212
namespace App\Service;
1313

1414
use App\Model\Cookbook;
15-
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
15+
use League\CommonMark\Extension\FrontMatter\Data\SymfonyYamlFrontMatterParser;
16+
use League\CommonMark\Extension\FrontMatter\FrontMatterParser;
17+
use League\CommonMark\Extension\FrontMatter\FrontMatterParserInterface;
1618

17-
class CookbookFactory
19+
final class CookbookFactory
1820
{
19-
public function __construct(
20-
private readonly CookbookParser $cookbookParser,
21-
private readonly UrlGeneratorInterface $urlGenerator,
22-
) {
21+
private FrontMatterParserInterface $frontMatterParser;
22+
23+
public function __construct()
24+
{
25+
$this->frontMatterParser = new FrontMatterParser(new SymfonyYamlFrontMatterParser());
2326
}
2427

25-
public function buildFromFile(\SplFileInfo $file): Cookbook
28+
public function createFromFile(string $file): Cookbook
2629
{
27-
$content = $file->getContents();
30+
if (!file_exists($file)) {
31+
throw new \InvalidArgumentException(\sprintf('File "%s" not found.', $file));
32+
}
33+
34+
$content = file_get_contents($file);
35+
36+
if (!\is_array($frontMatter = $this->frontMatterParser->parse($content)->getFrontMatter())) {
37+
throw new \RuntimeException(\sprintf('Cookbook file "%s" does not contains Front Matter data.', $file));
38+
}
39+
40+
if (!isset($frontMatter['title']) || !\is_string($frontMatter['title'])) {
41+
throw new \RuntimeException('Missing title in Front Matter.');
42+
}
43+
if (!isset($frontMatter['description']) || !\is_string($frontMatter['description'])) {
44+
throw new \RuntimeException('Missing description in Front Matter.');
45+
}
46+
if (!isset($frontMatter['image']) || !\is_string($frontMatter['image'])) {
47+
throw new \RuntimeException('Missing image in Front Matter.');
48+
}
49+
if (!isset($frontMatter['tags']) || !\is_array($frontMatter['tags'])) {
50+
throw new \RuntimeException('Missing tags in Front Matter.');
51+
}
2852

2953
return new Cookbook(
30-
title: $this->cookbookParser->getTitle($content),
31-
description: $this->cookbookParser->getDescriptions($content),
32-
route: $this->urlGenerator->generate('app_cookbook_show', ['slug' => $file->getBasename('.md')]),
33-
image: $this->cookbookParser->getImage($content),
54+
title: $frontMatter['title'],
55+
slug: str_replace('_', '-', basename($file, '.md')),
56+
image: $frontMatter['image'],
57+
description: $frontMatter['description'],
3458
content: $content,
35-
tags: $this->cookbookParser->getTags($content),
59+
tags: $frontMatter['tags'],
3660
);
3761
}
3862
}

ux.symfony.com/src/Service/CookbookParser.php

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)