Skip to content

Commit 858f0ac

Browse files
committed
Highlight code & simplify render
1 parent 3dd7c50 commit 858f0ac

File tree

5 files changed

+31
-54
lines changed

5 files changed

+31
-54
lines changed
Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
11
.Cookbook {
2-
.tags {
3-
display: flex;
4-
justify-content: center;
5-
align-items: center;
6-
width: 100%;
7-
gap: 1rem;
8-
text-decoration: none;
9-
list-style: none;
10-
margin-bottom: 3rem;
11-
12-
li {
13-
background-color: rgb(74 29 150);
14-
color: rgb(202 191 253);
15-
font-weight: 500;
16-
font-size: 0.75rem;
17-
line-height: 1rem;
18-
padding: .125rem .625rem;
19-
border-radius: 0.25rem;
20-
}
21-
}
222

233
.image-title {
244
overflow: hidden;
255
width: auto;
266
border-radius: .75rem;
27-
margin-bottom: 3rem;
287
aspect-ratio: 16 / 9;
8+
max-width: 1280px;
299

3010
img {
3111
display: block;
@@ -53,15 +33,18 @@
5333
}
5434

5535
h4 {
56-
margin-top: 3rem;
57-
margin-bottom: 1rem;
58-
}
36+
margin-top: 3rem;
37+
margin-bottom: 1rem;
38+
}
5939
}
6040

6141
pre {
6242
margin-block: 2rem;
6343
border-radius: .75rem;
6444
background-color: #0A0A0A;
6545
padding: 1rem 1.5rem;
46+
color: #d7e2e3;
47+
font-size: 1rem;
48+
line-height: 1.5;
6649
}
6750
}

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/src/Model/Cookbook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
public string $image,
2323
public string $description,
2424
public string $content,
25-
public array $tags = [],
25+
public array $tags,
2626
) {
2727
}
2828
}

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

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
namespace App\Service;
1313

1414
use App\Model\Cookbook;
15-
use League\CommonMark\Environment\Environment;
16-
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
17-
use League\CommonMark\Extension\FrontMatter\FrontMatterExtension;
18-
use League\CommonMark\Extension\FrontMatter\FrontMatterProviderInterface;
19-
use League\CommonMark\MarkdownConverter;
15+
use League\CommonMark\Extension\FrontMatter\Data\SymfonyYamlFrontMatterParser;
16+
use League\CommonMark\Extension\FrontMatter\FrontMatterParser;
17+
use League\CommonMark\Extension\FrontMatter\FrontMatterParserInterface;
2018

2119
final class CookbookFactory
2220
{
23-
private MarkdownConverter $converter;
21+
private FrontMatterParserInterface $frontMatterParser;
22+
23+
public function __construct()
24+
{
25+
$this->frontMatterParser = new FrontMatterParser(new SymfonyYamlFrontMatterParser());
26+
}
2427

2528
public function createFromFile(string $file): Cookbook
2629
{
@@ -30,14 +33,10 @@ public function createFromFile(string $file): Cookbook
3033

3134
$content = file_get_contents($file);
3235

33-
$parsedContent = $this->getConverter()->convert($content);
34-
if (!$parsedContent instanceof FrontMatterProviderInterface) {
35-
throw new \RuntimeException('Unable to parse the cookbook.');
36-
}
37-
38-
if (!\is_array($frontMatter = $parsedContent->getFrontMatter())) {
36+
if (!\is_array($frontMatter = $this->frontMatterParser->parse($content)->getFrontMatter())) {
3937
throw new \RuntimeException(\sprintf('Cookbook file "%s" does not contains Front Matter data.', $file));
4038
}
39+
4140
if (!isset($frontMatter['title']) || !\is_string($frontMatter['title'])) {
4241
throw new \RuntimeException('Missing title in Front Matter.');
4342
}
@@ -56,21 +55,8 @@ public function createFromFile(string $file): Cookbook
5655
slug: str_replace('_', '-', basename($file, '.md')),
5756
image: $frontMatter['image'],
5857
description: $frontMatter['description'],
59-
content: $parsedContent->getContent(),
58+
content: $content,
6059
tags: $frontMatter['tags'],
6160
);
6261
}
63-
64-
private function getConverter(): MarkdownConverter
65-
{
66-
if (!isset($this->converter)) {
67-
$environment = new Environment();
68-
$environment->addExtension(new CommonMarkCoreExtension());
69-
$environment->addExtension(new FrontMatterExtension());
70-
71-
$this->converter = new MarkdownConverter($environment);
72-
}
73-
74-
return $this->converter;
75-
}
7662
}

ux.symfony.com/templates/cookbook/show.html.twig

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,24 @@
4141
</div>
4242
<div class="pt-4">
4343
<div class="image-title">
44-
<img src="{{ asset('images/cookbook/%s-1280x720.png'|format(cookbook.slug)) }}" alt="{{ cookbook.title }} Illustration" />
44+
<img src="{{ asset('images/cookbook/%s-1280x720.png'|format(cookbook.slug)) }}"
45+
alt="{{ cookbook.title }} Illustration"
46+
width="1280" height="720"
47+
/>
4548
</div>
4649
</div>
4750
</div>
4851
</div>
4952

5053
<div class="container container-xl x-4 pt-4 px-md-5 pt-md-5">
51-
<div class="content" style="max-width: 75ch;margin-inline: auto;font-size: 1.25rem;line-height: 1.75;font-weight: 200;">
52-
{{ cookbook.content|markdown_to_html }}
54+
<div class="content" style="max-width: 75ch;margin-inline: auto;font-size: 1.25rem;line-height: 1.75;font-weight: 300;">
55+
{{ cookbook.content|raw|markdown_to_html }}
5356
</div>
5457
</div>
5558

5659
</article>
5760
{% endblock %}
61+
62+
{% block aside %}
63+
{{ include('_aside.html.twig') }}
64+
{% endblock %}

0 commit comments

Comments
 (0)