Skip to content

Commit 48eb5d8

Browse files
authored
feat: enable embed support (#230)
* feat: bump deps * feat: embed support
1 parent 4d1e998 commit 48eb5d8

File tree

11 files changed

+96
-46
lines changed

11 files changed

+96
-46
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"require": {
66
"php": "^8.3",
77
"ext-zlib": "*",
8-
"bentools/cartesian-product": "^1.4",
8+
"bentools/cartesian-product": "^2.0",
9+
"embed/embed": "^4.0",
910
"jsw/commonmark-figure-extension": "^1.1",
1011
"league/commonmark": "^2.3",
12+
"nyholm/psr7": "^1.0",
1113
"phpdocumentor/type-resolver": "^1.0",
1214
"phpstan/phpdoc-parser": "^1.0",
1315
"presta/sitemap-bundle": "^4.0",

config/services.yaml

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ services:
2626
sigwin_yassg.abstract.database.storage.filesystem_storage_type:
2727
class: Sigwin\YASSG\Storage\FilesystemStorage
2828
tags:
29-
-
30-
name: sigwin_yassg.database.storage.type
29+
- name: sigwin_yassg.database.storage.type
3130
type: filesystem
3231
sigwin_yassg.abstract.database.storage.memory_storage_type:
3332
class: Sigwin\YASSG\Storage\MemoryStorage
3433
tags:
35-
-
36-
name: sigwin_yassg.database.storage.type
34+
- name: sigwin_yassg.database.storage.type
3735
type: memory
3836

3937
Sigwin\YASSG\DatabaseProvider:
@@ -43,41 +41,36 @@ services:
4341
sigwin_yassg.expression_language:
4442
class: Symfony\Component\ExpressionLanguage\ExpressionLanguage
4543
calls:
46-
-
47-
registerProvider: [ '@Sigwin\YASSG\Bridge\Symfony\ExpressionLanguage\FunctionProvider' ]
44+
- registerProvider: [ '@Sigwin\YASSG\Bridge\Symfony\ExpressionLanguage\FunctionProvider' ]
4845

4946
Sigwin\YASSG\Permutator:
5047
$expressionLanguage: '@sigwin_yassg.expression_language'
5148

5249
sigwin_yassg.serializer.denormalizer.localizing:
5350
class: Sigwin\YASSG\Bridge\Symfony\Serializer\Normalizer\LocalizingNormalizer
5451
tags:
55-
-
56-
name: serializer.normalizer
52+
- name: serializer.normalizer
5753
priority: 3000
5854
sigwin_yassg.serializer.denormalizer.collection:
5955
class: Sigwin\YASSG\Bridge\Symfony\Serializer\Normalizer\CollectionNormalizer
6056
arguments:
6157
$expressionLanguage: '@sigwin_yassg.expression_language'
6258
tags:
63-
-
64-
name: serializer.normalizer
59+
- name: serializer.normalizer
6560
priority: 5000
6661
sigwin_yassg.serializer.denormalizer.expression:
6762
class: Sigwin\YASSG\Bridge\Symfony\Serializer\Normalizer\ExpressionNormalizer
6863
arguments:
6964
$expressionLanguage: '@sigwin_yassg.expression_language'
7065
tags:
71-
-
72-
name: serializer.normalizer
66+
- name: serializer.normalizer
7367
priority: 4000
7468
sigwin_yassg.serializer.denormalizer.locator:
7569
class: Sigwin\YASSG\Bridge\Symfony\Serializer\Normalizer\ResourceLocatorNormalizer
7670
arguments:
7771
$locator: '@file_locator'
7872
tags:
79-
-
80-
name: serializer.normalizer
73+
- name: serializer.normalizer
8174
priority: 3000
8275

8376
sigwin_yassg.fragment.renderer.inline:
@@ -100,12 +93,22 @@ services:
10093
sigwin_yassg.file_decoder.yaml_file_decoder:
10194
class: Sigwin\YASSG\Decoder\YamlFileDecoder
10295
tags:
103-
-
104-
name: sigwin_yassg.file_decoder
96+
- name: sigwin_yassg.file_decoder
97+
98+
Embed\Embed:
99+
calls:
100+
- setSettings:
101+
- "oembed:query_parameters":
102+
maxwidth: 800
103+
maxheight: 600
105104

106105
League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension: ~
107106
League\CommonMark\Extension\FrontMatter\FrontMatterExtension: ~
108107
League\CommonMark\Extension\Table\TableExtension: ~
108+
League\CommonMark\Extension\Embed\EmbedExtension: ~
109+
League\CommonMark\Extension\Embed\Bridge\OscaroteroEmbedAdapter:
110+
$embed: '@Embed\Embed'
111+
109112
League\CommonMark\Extension\Footnote\FootnoteExtension: ~
110113
League\CommonMark\Extension\Attributes\AttributesExtension: ~
111114
League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension: ~
@@ -116,27 +119,22 @@ services:
116119
Spatie\CommonMarkHighlighter\IndentedCodeRenderer: ~
117120

118121
League\CommonMark\Environment\Environment:
122+
arguments:
123+
$config:
124+
embed:
125+
adapter: '@League\CommonMark\Extension\Embed\Bridge\OscaroteroEmbedAdapter'
119126
calls:
120-
-
121-
addExtension: [ '@League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension' ]
122-
-
123-
addExtension: [ '@League\CommonMark\Extension\FrontMatter\FrontMatterExtension' ]
124-
-
125-
addExtension: [ '@League\CommonMark\Extension\Table\TableExtension' ]
126-
-
127-
addExtension: [ '@League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension' ]
128-
-
129-
addExtension: [ '@League\CommonMark\Extension\TableOfContents\TableOfContentsExtension' ]
130-
-
131-
addExtension: [ '@League\CommonMark\Extension\Footnote\FootnoteExtension' ]
132-
-
133-
addExtension: [ '@League\CommonMark\Extension\Attributes\AttributesExtension' ]
134-
-
135-
addExtension: [ '@JSW\Figure\FigureExtension' ]
136-
-
137-
addRenderer: [ League\CommonMark\Extension\CommonMark\Node\Block\FencedCode, '@Spatie\CommonMarkHighlighter\FencedCodeRenderer', 10 ]
138-
-
139-
addRenderer: [ League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode, '@Spatie\CommonMarkHighlighter\IndentedCodeRenderer', 10 ]
127+
- addExtension: [ '@League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension' ]
128+
- addExtension: [ '@League\CommonMark\Extension\Embed\EmbedExtension' ]
129+
- addExtension: [ '@League\CommonMark\Extension\FrontMatter\FrontMatterExtension' ]
130+
- addExtension: [ '@League\CommonMark\Extension\Table\TableExtension' ]
131+
- addExtension: [ '@League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension' ]
132+
- addExtension: [ '@League\CommonMark\Extension\TableOfContents\TableOfContentsExtension' ]
133+
- addExtension: [ '@League\CommonMark\Extension\Footnote\FootnoteExtension' ]
134+
- addExtension: [ '@League\CommonMark\Extension\Attributes\AttributesExtension' ]
135+
- addExtension: [ '@JSW\Figure\FigureExtension' ]
136+
- addRenderer: [ League\CommonMark\Extension\CommonMark\Node\Block\FencedCode, '@Spatie\CommonMarkHighlighter\FencedCodeRenderer', 10 ]
137+
- addRenderer: [ League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode, '@Spatie\CommonMarkHighlighter\IndentedCodeRenderer', 10 ]
140138
League\CommonMark\Environment\EnvironmentInterface: '@League\CommonMark\Environment\Environment'
141139

142140
League\CommonMark\MarkdownConverter: ~
@@ -146,8 +144,7 @@ services:
146144
arguments:
147145
- '@League\CommonMark\ConverterInterface'
148146
tags:
149-
-
150-
name: sigwin_yassg.file_decoder
147+
- name: sigwin_yassg.file_decoder
151148

152149
Sigwin\YASSG\Bridge\Symfony\Routing\Generator\GlobalVariableUrlGenerator:
153150
decorates: Symfony\Component\Routing\Generator\UrlGeneratorInterface

psalm.baseline.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,9 @@
712712
<MixedArgument>
713713
<code><![CDATA[$parameters]]></code>
714714
</MixedArgument>
715+
<InternalMethod>
716+
<code><![CDATA[combinations($variables)]]></code>
717+
</InternalMethod>
715718
<MixedArgumentTypeCoercion>
716719
<code><![CDATA[$route]]></code>
717720
<code><![CDATA[$route]]></code>

src/Permutator.php

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

1616
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1717

18-
use function BenTools\CartesianProduct\cartesian_product;
18+
use function BenTools\CartesianProduct\combinations;
1919

2020
final readonly class Permutator
2121
{
@@ -49,13 +49,17 @@ public function permute(): \Traversable
4949
}
5050

5151
foreach ($spec['catalog'] as $variable => $expression) {
52-
$variables[$variable] = $this->expressionLanguage->evaluate(
52+
$catalog = $this->expressionLanguage->evaluate(
5353
$expression,
5454
['provider' => $this->provider]
5555
);
56+
if (! is_iterable($catalog)) {
57+
throw new \InvalidArgumentException('Catalog for variable "'.$variable.'" must be iterable, got '.\gettype($catalog));
58+
}
59+
$variables[$variable] = $catalog;
5660
}
5761

58-
foreach (cartesian_product($variables) as $parameters) {
62+
foreach (combinations($variables) as $parameters) {
5963
yield new Location(
6064
new Route($route, $parameters),
6165
new BuildOptions($spec['options']['headers'] ?? null)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Embeds
3+
slug: embeds
4+
publishedAt: "2023-10-01 00:00:00"
5+
---
6+
7+
https://www.youtube.com/watch?v=oGcLClv_IFU
8+
9+
https://x.com/dkarlovi/status/1784950485595623522
10+
11+
https://github.com/sigwinhq/yassg
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<script src="https://cdn.tailwindcss.com?plugins=typography"></script>
7+
8+
<title>Embeds</title>
9+
10+
<link rel="stylesheet" href="/sub/dir/another/assets/app.d4da4e7e.css" integrity="sha384-t9qUhz8OfBEKvYdnnNndPZAf+S5Q3p0dBnxLn+5SShoNhInHUF+Bu8WJTo+FQJYJ">
11+
</head>
12+
<body>
13+
14+
<main class="min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8">
15+
<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-xl">
16+
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10 prose">
17+
<h1>Embeds</h1>
18+
<p>01.10.2023. 00:00</p>
19+
<iframe width="800" height="450" src="https://www.youtube.com/embed/oGcLClv_IFU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen title="Your code coverage is LYING!"></iframe>
20+
<blockquote class="twitter-tweet" data-width="550"><p lang="en" dir="ltr">Using the code coverage percentage as a measure of quality of your codebase is a bad idea, here&#39;s what to do instead: <a href="https://twitter.com/hashtag/quality?src=hash&amp;ref_src=twsrc%5Etfw">#quality</a> <a href="https://twitter.com/hashtag/SoftwareEngineering?src=hash&amp;ref_src=twsrc%5Etfw">#SoftwareEngineering</a> <a href="https://twitter.com/hashtag/testing?src=hash&amp;ref_src=twsrc%5Etfw">#testing</a> <a href="https://t.co/94vpY6F4mC">https://t.co/94vpY6F4mC</a></p>&mdash; Dalibor Karlović (@dkarlovi) <a href="https://twitter.com/dkarlovi/status/1784950485595623522?ref_src=twsrc%5Etfw">April 29, 2024</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
21+
<p><a href="https://github.com/sigwinhq/yassg">https://github.com/sigwinhq/yassg</a></p>
22+
23+
</div>
24+
</div>
25+
</main>
26+
27+
<script src="/sub/dir/another/assets/runtime.4d1205b9.js" integrity="sha384-J2jFm3DPgrcqyvls0fZlS51nUYgiBB+JLwWiU5v7vxEbLwKolmaHrRuz4BjP6qaE"></script><script src="/sub/dir/another/assets/app.9267444a.js" integrity="sha384-WbAUi92ziCGFD1kGZRzpOP8Nxymnw5vXM3szOB1JmBrCU+MVGXBRReCttizXHDdI"></script>
28+
</body>
29+
</html>

tests/functional/site/fixtures/en/articles/1/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-xl">
1616
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10 prose">
1717
<h1>Articles</h1>
18+
<h2><a href="https://example.com/sub/dir/another/en/article/embeds/">Embeds</a></h2>
19+
<p>01.10.2023. 00:00</p>
1820
<h2><a href="https://example.com/sub/dir/another/en/article/images/">Images!</a></h2>
1921
<p><img src="/sub/dir/another/content/articles/images/image.669f7055.webp"></p>
2022
<p>20.07.2022. 12:35</p>
21-
<h2><a href="https://example.com/sub/dir/another/en/article/lists/">Lists!</a></h2>
22-
<p>19.07.2022. 12:13</p>
2323

2424
<ul>
2525
<li>

tests/functional/site/fixtures/en/articles/2/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-xl">
1616
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10 prose">
1717
<h1>Articles</h1>
18+
<h2><a href="https://example.com/sub/dir/another/en/article/lists/">Lists!</a></h2>
19+
<p>19.07.2022. 12:13</p>
1820
<h2><a href="https://example.com/sub/dir/another/en/article/titles/">Titles!</a></h2>
1921
<p>19.07.2022. 12:11</p>
20-
<h2><a href="https://example.com/sub/dir/another/en/article/paragraphs/">Paragraphs!</a></h2>
21-
<p>19.07.2022. 12:09</p>
2222

2323
<ul>
2424
<li>

tests/functional/site/fixtures/en/articles/3/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-xl">
1616
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10 prose">
1717
<h1>Articles</h1>
18+
<h2><a href="https://example.com/sub/dir/another/en/article/paragraphs/">Paragraphs!</a></h2>
19+
<p>19.07.2022. 12:09</p>
1820
<h2><a href="https://example.com/sub/dir/another/en/article/hello-world/">Hello World!</a></h2>
1921
<p>18.07.2022. 12:44</p>
2022

tests/functional/site/fixtures/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ <h1>Index</h1>
3434
<dd><a href="/sub/dir/another/en/">/sub/dir/another/en/</a></dd>
3535
<dt>article</dt>
3636

37+
<dd><a href="/sub/dir/another/en/article/embeds/">/sub/dir/another/en/article/embeds/</a></dd>
38+
3739
<dd><a href="/sub/dir/another/en/article/hello-world/">/sub/dir/another/en/article/hello-world/</a></dd>
3840

3941
<dd><a href="/sub/dir/another/en/article/images/">/sub/dir/another/en/article/images/</a></dd>

0 commit comments

Comments
 (0)