From 649c0856899091c1a18638a361194fc21200c8b9 Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Tue, 21 Nov 2023 11:01:11 +0100 Subject: [PATCH] [BUGFIX] Let Image sources respect relative and absolute links configuration --- packages/guides/src/Twig/AssetsExtension.php | 3 +- .../expected/hero-illustration.svg | 0 .../expected/images/hero2-illustration.svg | 0 .../image-absolute/expected/index.html | 35 ++++ .../expected/subfolder/subpage.html | 35 ++++ .../image-absolute/input/guides.xml | 7 + .../input/hero-illustration.svg | 0 .../input/images/hero2-illustration.svg | 0 .../{image => image-absolute}/input/index.rst | 0 .../input/subfolder/subpage.rst | 0 .../expected/hero-illustration.svg | 180 ++++++++++++++++++ .../expected/images/hero2-illustration.svg | 180 ++++++++++++++++++ .../expected/index.html | 0 .../expected/subfolder/subpage.html | 4 +- .../image-relative/input/guides.xml | 7 + .../input/hero-illustration.svg | 180 ++++++++++++++++++ .../input/images/hero2-illustration.svg | 180 ++++++++++++++++++ .../image-relative/input/index.rst | 27 +++ .../input/subfolder/subpage.rst | 20 ++ 19 files changed, 854 insertions(+), 4 deletions(-) rename tests/Integration/tests/body-elements/{image => image-absolute}/expected/hero-illustration.svg (100%) rename tests/Integration/tests/body-elements/{image => image-absolute}/expected/images/hero2-illustration.svg (100%) create mode 100644 tests/Integration/tests/body-elements/image-absolute/expected/index.html create mode 100644 tests/Integration/tests/body-elements/image-absolute/expected/subfolder/subpage.html create mode 100644 tests/Integration/tests/body-elements/image-absolute/input/guides.xml rename tests/Integration/tests/body-elements/{image => image-absolute}/input/hero-illustration.svg (100%) rename tests/Integration/tests/body-elements/{image => image-absolute}/input/images/hero2-illustration.svg (100%) rename tests/Integration/tests/body-elements/{image => image-absolute}/input/index.rst (100%) rename tests/Integration/tests/body-elements/{image => image-absolute}/input/subfolder/subpage.rst (100%) create mode 100644 tests/Integration/tests/body-elements/image-relative/expected/hero-illustration.svg create mode 100644 tests/Integration/tests/body-elements/image-relative/expected/images/hero2-illustration.svg rename tests/Integration/tests/body-elements/{image => image-relative}/expected/index.html (100%) rename tests/Integration/tests/body-elements/{image => image-relative}/expected/subfolder/subpage.html (85%) create mode 100644 tests/Integration/tests/body-elements/image-relative/input/guides.xml create mode 100644 tests/Integration/tests/body-elements/image-relative/input/hero-illustration.svg create mode 100644 tests/Integration/tests/body-elements/image-relative/input/images/hero2-illustration.svg create mode 100644 tests/Integration/tests/body-elements/image-relative/input/index.rst create mode 100644 tests/Integration/tests/body-elements/image-relative/input/subfolder/subpage.rst diff --git a/packages/guides/src/Twig/AssetsExtension.php b/packages/guides/src/Twig/AssetsExtension.php index f77c32652..274dd2048 100644 --- a/packages/guides/src/Twig/AssetsExtension.php +++ b/packages/guides/src/Twig/AssetsExtension.php @@ -91,8 +91,7 @@ public function asset(array $context, string $path): string { $outputPath = $this->copyAsset($context['env'] ?? null, $path); - // make it relative so it plays nice with the base tag in the HEAD - return trim($outputPath, '/'); + return $this->urlGenerator->generateInternalUrl($context['env'] ?? null, trim($outputPath, '/')); } /** diff --git a/tests/Integration/tests/body-elements/image/expected/hero-illustration.svg b/tests/Integration/tests/body-elements/image-absolute/expected/hero-illustration.svg similarity index 100% rename from tests/Integration/tests/body-elements/image/expected/hero-illustration.svg rename to tests/Integration/tests/body-elements/image-absolute/expected/hero-illustration.svg diff --git a/tests/Integration/tests/body-elements/image/expected/images/hero2-illustration.svg b/tests/Integration/tests/body-elements/image-absolute/expected/images/hero2-illustration.svg similarity index 100% rename from tests/Integration/tests/body-elements/image/expected/images/hero2-illustration.svg rename to tests/Integration/tests/body-elements/image-absolute/expected/images/hero2-illustration.svg diff --git a/tests/Integration/tests/body-elements/image-absolute/expected/index.html b/tests/Integration/tests/body-elements/image-absolute/expected/index.html new file mode 100644 index 000000000..43a823d0a --- /dev/null +++ b/tests/Integration/tests/body-elements/image-absolute/expected/index.html @@ -0,0 +1,35 @@ + +
+

Document Title

+ +

Lorem Ipsum Dolor.

+
+

A local image

+ + Alternative text + +
+ +
+

An image with absolute paths

+ + Alternative text + +
+ +
+

An image with relative paths

+ + Alternative text + +
+ +
+ + diff --git a/tests/Integration/tests/body-elements/image-absolute/expected/subfolder/subpage.html b/tests/Integration/tests/body-elements/image-absolute/expected/subfolder/subpage.html new file mode 100644 index 000000000..e3b183862 --- /dev/null +++ b/tests/Integration/tests/body-elements/image-absolute/expected/subfolder/subpage.html @@ -0,0 +1,35 @@ + + + + Subpage + + + + +
+

Subpage

+ +

Lorem Ipsum Dolor.

+
+

An image with absolute paths

+ + Alternative text + +
+ +
+

An image with relative paths

+ + Alternative text + +
+ +
+ + + + diff --git a/tests/Integration/tests/body-elements/image-absolute/input/guides.xml b/tests/Integration/tests/body-elements/image-absolute/input/guides.xml new file mode 100644 index 000000000..1e9db742d --- /dev/null +++ b/tests/Integration/tests/body-elements/image-absolute/input/guides.xml @@ -0,0 +1,7 @@ + + + diff --git a/tests/Integration/tests/body-elements/image/input/hero-illustration.svg b/tests/Integration/tests/body-elements/image-absolute/input/hero-illustration.svg similarity index 100% rename from tests/Integration/tests/body-elements/image/input/hero-illustration.svg rename to tests/Integration/tests/body-elements/image-absolute/input/hero-illustration.svg diff --git a/tests/Integration/tests/body-elements/image/input/images/hero2-illustration.svg b/tests/Integration/tests/body-elements/image-absolute/input/images/hero2-illustration.svg similarity index 100% rename from tests/Integration/tests/body-elements/image/input/images/hero2-illustration.svg rename to tests/Integration/tests/body-elements/image-absolute/input/images/hero2-illustration.svg diff --git a/tests/Integration/tests/body-elements/image/input/index.rst b/tests/Integration/tests/body-elements/image-absolute/input/index.rst similarity index 100% rename from tests/Integration/tests/body-elements/image/input/index.rst rename to tests/Integration/tests/body-elements/image-absolute/input/index.rst diff --git a/tests/Integration/tests/body-elements/image/input/subfolder/subpage.rst b/tests/Integration/tests/body-elements/image-absolute/input/subfolder/subpage.rst similarity index 100% rename from tests/Integration/tests/body-elements/image/input/subfolder/subpage.rst rename to tests/Integration/tests/body-elements/image-absolute/input/subfolder/subpage.rst diff --git a/tests/Integration/tests/body-elements/image-relative/expected/hero-illustration.svg b/tests/Integration/tests/body-elements/image-relative/expected/hero-illustration.svg new file mode 100644 index 000000000..002f8feff --- /dev/null +++ b/tests/Integration/tests/body-elements/image-relative/expected/hero-illustration.svg @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Integration/tests/body-elements/image-relative/expected/images/hero2-illustration.svg b/tests/Integration/tests/body-elements/image-relative/expected/images/hero2-illustration.svg new file mode 100644 index 000000000..002f8feff --- /dev/null +++ b/tests/Integration/tests/body-elements/image-relative/expected/images/hero2-illustration.svg @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Integration/tests/body-elements/image/expected/index.html b/tests/Integration/tests/body-elements/image-relative/expected/index.html similarity index 100% rename from tests/Integration/tests/body-elements/image/expected/index.html rename to tests/Integration/tests/body-elements/image-relative/expected/index.html diff --git a/tests/Integration/tests/body-elements/image/expected/subfolder/subpage.html b/tests/Integration/tests/body-elements/image-relative/expected/subfolder/subpage.html similarity index 85% rename from tests/Integration/tests/body-elements/image/expected/subfolder/subpage.html rename to tests/Integration/tests/body-elements/image-relative/expected/subfolder/subpage.html index 6aabf492a..e263003c6 100644 --- a/tests/Integration/tests/body-elements/image/expected/subfolder/subpage.html +++ b/tests/Integration/tests/body-elements/image-relative/expected/subfolder/subpage.html @@ -7,7 +7,7 @@

Subpage

An image with absolute paths

Alternative text @@ -16,7 +16,7 @@

An image with absolute paths

An image with relative paths

Alternative text diff --git a/tests/Integration/tests/body-elements/image-relative/input/guides.xml b/tests/Integration/tests/body-elements/image-relative/input/guides.xml new file mode 100644 index 000000000..3f4740587 --- /dev/null +++ b/tests/Integration/tests/body-elements/image-relative/input/guides.xml @@ -0,0 +1,7 @@ + + + diff --git a/tests/Integration/tests/body-elements/image-relative/input/hero-illustration.svg b/tests/Integration/tests/body-elements/image-relative/input/hero-illustration.svg new file mode 100644 index 000000000..002f8feff --- /dev/null +++ b/tests/Integration/tests/body-elements/image-relative/input/hero-illustration.svg @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Integration/tests/body-elements/image-relative/input/images/hero2-illustration.svg b/tests/Integration/tests/body-elements/image-relative/input/images/hero2-illustration.svg new file mode 100644 index 000000000..002f8feff --- /dev/null +++ b/tests/Integration/tests/body-elements/image-relative/input/images/hero2-illustration.svg @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Integration/tests/body-elements/image-relative/input/index.rst b/tests/Integration/tests/body-elements/image-relative/input/index.rst new file mode 100644 index 000000000..4c821a696 --- /dev/null +++ b/tests/Integration/tests/body-elements/image-relative/input/index.rst @@ -0,0 +1,27 @@ +============== +Document Title +============== + +Lorem Ipsum Dolor. + +A local image +============= + +.. image:: hero-illustration.svg + :width: 400 + :alt: Alternative text + +An image with absolute paths +============================ + +.. image:: /images/hero2-illustration.svg + :width: 400 + :alt: Alternative text + + +An image with relative paths +============================ + +.. image:: images/hero2-illustration.svg + :width: 400 + :alt: Alternative text diff --git a/tests/Integration/tests/body-elements/image-relative/input/subfolder/subpage.rst b/tests/Integration/tests/body-elements/image-relative/input/subfolder/subpage.rst new file mode 100644 index 000000000..a059b255f --- /dev/null +++ b/tests/Integration/tests/body-elements/image-relative/input/subfolder/subpage.rst @@ -0,0 +1,20 @@ +======= +Subpage +======= + +Lorem Ipsum Dolor. + +An image with absolute paths +============================ + +.. image:: /images/hero2-illustration.svg + :width: 400 + :alt: Alternative text + + +An image with relative paths +============================ + +.. image:: ../images/hero2-illustration.svg + :width: 400 + :alt: Alternative text