Skip to content

Commit d513550

Browse files
committed
minor #18844 Fix the local doc build (javiereguiluz)
This PR was merged into the 5.4 branch. Discussion ---------- Fix the local doc build Fixes #18187. Now, pages inside subdirectories show the correct CSS assets and images are rendered too. Commits ------- 080f8df Fix the local doc build
2 parents 0453493 + 080f8df commit d513550

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

_build/build.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@
5252
foreach (new RegexIterator($iterator, '/^.+\.html$/i', RegexIterator::GET_MATCH) as $match) {
5353
$htmlFilePath = array_shift($match);
5454
$htmlContents = file_get_contents($htmlFilePath);
55-
file_put_contents($htmlFilePath, str_replace('<head>', '<head><base href="/">', $htmlContents));
55+
56+
$htmlRelativeFilePath = str_replace($outputDir.'/', '', $htmlFilePath);
57+
$subdirLevel = substr_count($htmlRelativeFilePath, '/');
58+
$baseHref = str_repeat('../', $subdirLevel);
59+
60+
$htmlContents = str_replace('<head>', '<head><base href="'.$baseHref.'">', $htmlContents);
61+
$htmlContents = str_replace('<img src="/_images/', '<img src="_images/', $htmlContents);
62+
file_put_contents($htmlFilePath, $htmlContents);
5663
}
5764

5865
foreach (new RegexIterator($iterator, '/^.+\.css/i', RegexIterator::GET_MATCH) as $match) {

0 commit comments

Comments
 (0)