Skip to content

Commit c1c43c2

Browse files
committed
[TASK] Handle "valid Document entries" as absolute document paths
1 parent 653be76 commit c1c43c2

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

packages/guides/src/UrlGenerator.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,20 @@ public function generateOutputUrlFromDocumentPath(
9494
string $outputFormat,
9595
string|null $anchor = null,
9696
): string {
97+
if ($validDocumentEntry) {
98+
$linkedDocument = '/' . $linkedDocument;
99+
}
100+
101+
$fileUrl = $this->createFileUrl($linkedDocument, $outputFormat, $anchor);
97102
if (UriInfo::isAbsolutePath(Uri::createFromString($linkedDocument))) {
98-
return $destinationPath . $this->createFileUrl($linkedDocument, $outputFormat, $anchor);
103+
return $destinationPath . $fileUrl;
99104
}
100105

101106
$baseUrl = ltrim($this->absoluteUrl($destinationPath, $currentDirectory), '/');
102107

103-
if ($validDocumentEntry) {
104-
return $destinationPath . '/'
105-
. $this->createFileUrl($linkedDocument, $outputFormat, $anchor);
106-
}
107-
108108
return $this->canonicalUrl(
109109
$baseUrl,
110-
$this->createFileUrl($linkedDocument, $outputFormat, $anchor),
110+
$fileUrl,
111111
);
112112
}
113113
}

packages/guides/tests/unit/UrlGeneratorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,20 @@ public static function documentPathProvider(): array
191191
'linkedDocument' => '../references/installing',
192192
'result' => 'guide/references/installing.txt',
193193
],
194+
'relative document path up in subdirectory' => [
195+
'currentDirectory' => 'getting-started/something',
196+
'destinationPath' => 'guide',
197+
'validDocumentEntry' => false,
198+
'linkedDocument' => '../references/installing',
199+
'result' => 'guide/getting-started/references/installing.txt',
200+
],
201+
'relative document path two up in directory' => [
202+
'currentDirectory' => 'getting-started/something',
203+
'destinationPath' => 'guide',
204+
'validDocumentEntry' => false,
205+
'linkedDocument' => '../../references/installing',
206+
'result' => 'guide/references/installing.txt',
207+
],
194208
];
195209
}
196210
}

0 commit comments

Comments
 (0)