Skip to content

Commit 92c27b0

Browse files
committed
[TASK] Move "valid Document entries" handling hack to renderContext
1 parent c1c43c2 commit 92c27b0

File tree

4 files changed

+9
-20
lines changed

4 files changed

+9
-20
lines changed

packages/guides/src/RenderContext.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,17 @@ public function canonicalUrl(string $url): string
9494
return $this->urlGenerator->canonicalUrl($this->getDirName(), $url);
9595
}
9696

97-
public function relativeDocUrl(string $filename, string|null $anchor = null): string
97+
public function relativeDocUrl(string $linkedDocument, string|null $anchor = null): string
9898
{
99+
if ($this->projectNode->findDocumentEntry($linkedDocument) !== null) {
100+
// todo: this is a hack, existing documents are expected to be handled like absolute links in some places
101+
$linkedDocument = '/' . $linkedDocument;
102+
}
103+
99104
return $this->urlGenerator->generateOutputUrlFromDocumentPath(
100105
$this->getDirName(),
101106
$this->destinationPath,
102-
// Todo: it does not really make sense to treat relavtive paths that are found in the project node differently?
103-
$this->projectNode->findDocumentEntry($filename) !== null,
104-
$filename,
107+
$linkedDocument,
105108
$this->outputFormat,
106109
$anchor,
107110
);

packages/guides/src/UrlGenerator.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,10 @@ public function createFileUrl(string $filename, string $outputFormat = 'html', s
8989
public function generateOutputUrlFromDocumentPath(
9090
string $currentDirectory,
9191
string $destinationPath,
92-
bool $validDocumentEntry,
9392
string $linkedDocument,
9493
string $outputFormat,
9594
string|null $anchor = null,
9695
): string {
97-
if ($validDocumentEntry) {
98-
$linkedDocument = '/' . $linkedDocument;
99-
}
100-
10196
$fileUrl = $this->createFileUrl($linkedDocument, $outputFormat, $anchor);
10297
if (UriInfo::isAbsolutePath(Uri::createFromString($linkedDocument))) {
10398
return $destinationPath . $fileUrl;

packages/guides/src/UrlGeneratorInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function createFileUrl(string $filename, string $outputFormat = 'html', s
3434
public function generateOutputUrlFromDocumentPath(
3535
string $currentDirectory,
3636
string $destinationPath,
37-
bool $validDocumentEntry,
3837
string $linkedDocument,
3938
string $outputFormat,
4039
string|null $anchor = null,

packages/guides/tests/unit/UrlGeneratorTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ public static function abstractUrlProvider(): array
142142
public function testRelativeDocUrl(
143143
string $currentDirectory,
144144
string $destinationPath,
145-
bool $validDocumentEntry,
146145
string $linkedDocument,
147146
string $result,
148147
string|null $anchor = null,
@@ -151,7 +150,6 @@ public function testRelativeDocUrl(
151150
self::assertSame($result, $urlGenerator->generateOutputUrlFromDocumentPath(
152151
$currentDirectory,
153152
$destinationPath,
154-
$validDocumentEntry,
155153
$linkedDocument,
156154
'txt',
157155
$anchor,
@@ -165,43 +163,37 @@ public static function documentPathProvider(): array
165163
'relative document' => [
166164
'currentDirectory' => 'getting-started',
167165
'destinationPath' => 'guide',
168-
'validDocumentEntry' => false,
169166
'linkedDocument' => 'installing',
170167
'result' => 'guide/getting-started/installing.txt',
171168
],
172169
'absolute document path' => [
173170
'currentDirectory' => 'getting-started',
174171
'destinationPath' => 'guide',
175-
'validDocumentEntry' => false,
176172
'linkedDocument' => '/installing',
177173
'result' => 'guide/installing.txt',
178174
],
179-
'relative document path with anchor' => [
175+
'absolute document path with anchor' => [
180176
'currentDirectory' => 'getting-started',
181177
'destinationPath' => 'guide',
182-
'validDocumentEntry' => true,
183-
'linkedDocument' => 'getting-started/configuration',
178+
'linkedDocument' => '/getting-started/configuration',
184179
'result' => 'guide/getting-started/configuration.txt#composer',
185180
'anchor' => 'composer',
186181
],
187182
'relative document path up in directory' => [
188183
'currentDirectory' => 'getting-started',
189184
'destinationPath' => 'guide',
190-
'validDocumentEntry' => false,
191185
'linkedDocument' => '../references/installing',
192186
'result' => 'guide/references/installing.txt',
193187
],
194188
'relative document path up in subdirectory' => [
195189
'currentDirectory' => 'getting-started/something',
196190
'destinationPath' => 'guide',
197-
'validDocumentEntry' => false,
198191
'linkedDocument' => '../references/installing',
199192
'result' => 'guide/getting-started/references/installing.txt',
200193
],
201194
'relative document path two up in directory' => [
202195
'currentDirectory' => 'getting-started/something',
203196
'destinationPath' => 'guide',
204-
'validDocumentEntry' => false,
205197
'linkedDocument' => '../../references/installing',
206198
'result' => 'guide/references/installing.txt',
207199
],

0 commit comments

Comments
 (0)