Skip to content

Commit 41f5312

Browse files
Fix importing bard assets (#109)
* Fix importing failed assets * Fix asset src * Fix tests * code style --------- Co-authored-by: Duncan McClean <duncan@duncanmcclean.com>
1 parent 873ed15 commit 41f5312

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Transformers/BardTransformer.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,19 @@ private function mapProsemirrorNodes(array $node): ?array
6060
]
6161
);
6262

63-
$asset = $assetContainer->asset(path: $transformer->transform($node['attrs']['src']));
63+
$path = $transformer->transform($node['attrs']['src']);
64+
65+
if (! $path) {
66+
return null;
67+
}
68+
69+
$asset = $assetContainer->asset(path: $path);
6470

6571
if (! $asset) {
6672
return null;
6773
}
6874

69-
$node['attrs']['src'] = $asset->id();
75+
$node['attrs']['src'] = 'asset::'.$asset->id();
7076
}
7177

7278
if (isset($node['content'])) {

tests/Transformers/BardTransformerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function it_handles_images()
178178
[
179179
'type' => 'image',
180180
'attrs' => [
181-
'src' => 'assets::2024/10/image.png',
181+
'src' => 'asset::assets::2024/10/image.png',
182182
],
183183
],
184184
], $output);
@@ -221,7 +221,7 @@ public function it_handles_nested_images()
221221
[
222222
'type' => 'image',
223223
'attrs' => [
224-
'src' => 'assets::2024/10/image.png',
224+
'src' => 'asset::assets::2024/10/image.png',
225225
],
226226
],
227227
],
@@ -305,7 +305,7 @@ public function it_downloads_images()
305305
[
306306
'type' => 'image',
307307
'attrs' => [
308-
'src' => 'assets::2024/10/image.png',
308+
'src' => 'asset::assets::2024/10/image.png',
309309
],
310310
],
311311
], $output);
@@ -353,7 +353,7 @@ public function it_downloads_images_and_stores_them_in_configured_folder()
353353
[
354354
'type' => 'image',
355355
'attrs' => [
356-
'src' => 'assets::custom-folder/image.png',
356+
'src' => 'asset::assets::custom-folder/image.png',
357357
],
358358
],
359359
], $output);

0 commit comments

Comments
 (0)