Skip to content

Commit

Permalink
Merge pull request #1133 from phpDocumentor/fix/relative-image-urls
Browse files Browse the repository at this point in the history
[FIX] use canonicalUrl to fetch images
  • Loading branch information
jaapio authored Oct 11, 2024
2 parents 0adfe93 + 5f0dfc3 commit 1243604
Show file tree
Hide file tree
Showing 13 changed files with 438 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/guides/src/Twig/AssetsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,27 @@ private function copyAsset(
}

$canonicalUrl = $this->documentNameResolver->canonicalUrl($renderContext->getDirName(), $sourcePath);
$normalizedSourcePath = $this->documentNameResolver->canonicalUrl($renderContext->getDirName(), $sourcePath);

$outputPath = $this->documentNameResolver->absoluteUrl(
$renderContext->getDestinationPath(),
$canonicalUrl,
);

try {
if ($renderContext->getOrigin()->has($sourcePath) === false) {
if ($renderContext->getOrigin()->has($normalizedSourcePath) === false) {
$this->logger->error(
sprintf('Image reference not found "%s"', $sourcePath),
sprintf('Image reference not found "%s"', $normalizedSourcePath),
$renderContext->getLoggerInformation(),
);

return $outputPath;
}

$fileContents = $renderContext->getOrigin()->read($sourcePath);
$fileContents = $renderContext->getOrigin()->read($normalizedSourcePath);
if ($fileContents === false) {
$this->logger->error(
sprintf('Could not read image file "%s"', $sourcePath),
sprintf('Could not read image file "%s"', $normalizedSourcePath),
$renderContext->getLoggerInformation(),
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- content start -->
<div class="section" id="dir-2-title">
<h1>Dir 2 Title</h1>

<p>Lorem Ipsum Dolor.</p>


<p><img src="../../images/hero-illustration.svg" alt="Hero Illustrations"/></p>

</div>
<!-- content end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- content start -->
<div class="section" id="some-page-in-dir-2">
<h1>Some Page in dir 2</h1>

<p>Lorem Ipsum <code>Dolor</code>.</p>

</div>
<!-- content end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- content start -->
<div class="section" id="dir-1-title">
<h1>Dir 1 Title</h1>

<p>Lorem Ipsum Dolor.</p>


<p><img src="../images/hero-illustration.svg" alt="Hero Illustrations"/></p>

</div>
<!-- content end -->
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- content start -->
<div class="section" id="document-title">
<h1>Document Title</h1>

<p>Lorem Ipsum Dolor.</p>

</div>
<!-- content end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dir 2 Title

Lorem Ipsum Dolor.

![Hero Illustrations](../../images/hero-illustration.svg)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# Some Page in dir 2

Lorem Ipsum `Dolor`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dir 1 Title

Lorem Ipsum Dolor.

![Hero Illustrations](../images/hero-illustration.svg)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<guides xmlns="https://www.phpdoc.org/guides"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd"
theme="bootstrap"
input-format="md"
links-are-relative="1"
automatic-menu="true"
>
<extension class="phpDocumentor\Guides\Bootstrap"/>
</guides>
Loading

0 comments on commit 1243604

Please sign in to comment.