Skip to content

Commit 1243604

Browse files
authored
Merge pull request #1133 from phpDocumentor/fix/relative-image-urls
[FIX] use canonicalUrl to fetch images
2 parents 0adfe93 + 5f0dfc3 commit 1243604

File tree

13 files changed

+438
-4
lines changed

13 files changed

+438
-4
lines changed

packages/guides/src/Twig/AssetsExtension.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,27 @@ private function copyAsset(
156156
}
157157

158158
$canonicalUrl = $this->documentNameResolver->canonicalUrl($renderContext->getDirName(), $sourcePath);
159+
$normalizedSourcePath = $this->documentNameResolver->canonicalUrl($renderContext->getDirName(), $sourcePath);
160+
159161
$outputPath = $this->documentNameResolver->absoluteUrl(
160162
$renderContext->getDestinationPath(),
161163
$canonicalUrl,
162164
);
163165

164166
try {
165-
if ($renderContext->getOrigin()->has($sourcePath) === false) {
167+
if ($renderContext->getOrigin()->has($normalizedSourcePath) === false) {
166168
$this->logger->error(
167-
sprintf('Image reference not found "%s"', $sourcePath),
169+
sprintf('Image reference not found "%s"', $normalizedSourcePath),
168170
$renderContext->getLoggerInformation(),
169171
);
170172

171173
return $outputPath;
172174
}
173175

174-
$fileContents = $renderContext->getOrigin()->read($sourcePath);
176+
$fileContents = $renderContext->getOrigin()->read($normalizedSourcePath);
175177
if ($fileContents === false) {
176178
$this->logger->error(
177-
sprintf('Could not read image file "%s"', $sourcePath),
179+
sprintf('Could not read image file "%s"', $normalizedSourcePath),
178180
$renderContext->getLoggerInformation(),
179181
);
180182

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- content start -->
2+
<div class="section" id="dir-2-title">
3+
<h1>Dir 2 Title</h1>
4+
5+
<p>Lorem Ipsum Dolor.</p>
6+
7+
8+
<p><img src="../../images/hero-illustration.svg" alt="Hero Illustrations"/></p>
9+
10+
</div>
11+
<!-- content end -->
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- content start -->
2+
<div class="section" id="some-page-in-dir-2">
3+
<h1>Some Page in dir 2</h1>
4+
5+
<p>Lorem Ipsum <code>Dolor</code>.</p>
6+
7+
</div>
8+
<!-- content end -->
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- content start -->
2+
<div class="section" id="dir-1-title">
3+
<h1>Dir 1 Title</h1>
4+
5+
<p>Lorem Ipsum Dolor.</p>
6+
7+
8+
<p><img src="../images/hero-illustration.svg" alt="Hero Illustrations"/></p>
9+
10+
</div>
11+
<!-- content end -->
Lines changed: 180 additions & 0 deletions
Loading
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- content start -->
2+
<div class="section" id="document-title">
3+
<h1>Document Title</h1>
4+
5+
<p>Lorem Ipsum Dolor.</p>
6+
7+
</div>
8+
<!-- content end -->
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Dir 2 Title
2+
3+
Lorem Ipsum Dolor.
4+
5+
![Hero Illustrations](../../images/hero-illustration.svg)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Some Page in dir 2
3+
4+
Lorem Ipsum `Dolor`.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Dir 1 Title
2+
3+
Lorem Ipsum Dolor.
4+
5+
![Hero Illustrations](../images/hero-illustration.svg)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<guides xmlns="https://www.phpdoc.org/guides"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd"
5+
theme="bootstrap"
6+
input-format="md"
7+
links-are-relative="1"
8+
automatic-menu="true"
9+
>
10+
<extension class="phpDocumentor\Guides\Bootstrap"/>
11+
</guides>

0 commit comments

Comments
 (0)