Skip to content

Commit 49e5c8d

Browse files
committed
[TASK] Rename method and improve doc comments
1 parent 26c41c4 commit 49e5c8d

File tree

8 files changed

+18
-11
lines changed

8 files changed

+18
-11
lines changed

packages/guides/src/NodeRenderers/Html/MenuEntryRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function render(Node $node, RenderContext $renderContext): string
2828
$renderContext,
2929
'body/menu/menu-item.html.twig',
3030
[
31-
'url' => $renderContext->relativeDocUrl($node->getUrl(), $node->getValue()->getId()),
31+
'url' => $renderContext->generateCanonicalOutputUrl($node->getUrl(), $node->getValue()->getId()),
3232
'node' => $node,
3333
],
3434
);

packages/guides/src/ReferenceResolvers/DocReferenceResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext): boo
2525
return false;
2626
}
2727

28-
$node->setUrl($renderContext->relativeDocUrl($document->getFile()));
28+
$node->setUrl($renderContext->generateCanonicalOutputUrl($document->getFile()));
2929
if ($node->getValue() === '') {
3030
$node->setValue($document->getTitle()->toString());
3131
}

packages/guides/src/ReferenceResolvers/RefReferenceResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext): boo
2323
return false;
2424
}
2525

26-
$node->setUrl($renderContext->relativeDocUrl($target->getDocumentPath(), $target->getAnchor()));
26+
$node->setUrl($renderContext->generateCanonicalOutputUrl($target->getDocumentPath(), $target->getAnchor()));
2727
if ($node->getValue() === '') {
2828
$node->setValue($target->getTitle() ?? '');
2929
}

packages/guides/src/RenderContext.php

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

97-
public function relativeDocUrl(string $linkedDocument, string|null $anchor = null): string
97+
/**
98+
* Generate a canonical output URL with the configured file extension and anchor
99+
*/
100+
public function generateCanonicalOutputUrl(string $linkedDocument, string|null $anchor = null): string
98101
{
99102
if ($this->projectNode->findDocumentEntry($linkedDocument) !== null) {
100103
// todo: this is a hack, existing documents are expected to be handled like absolute links in some places

packages/guides/src/Twig/AssetsExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function renderNode(array $context, Node|array|null $node): string
114114
public function renderTarget(array $context, Target $target): string
115115
{
116116
if ($target instanceof InternalTarget) {
117-
return $this->getRenderContext($context)->relativeDocUrl($target->getDocumentPath(), $target->getAnchor());
117+
return $this->getRenderContext($context)->generateCanonicalOutputUrl($target->getDocumentPath(), $target->getAnchor());
118118
}
119119

120120
return $target->getUrl();
@@ -146,7 +146,7 @@ public function renderMenu(array $context, string $menuType, int $maxMenuCount =
146146
/** @param array{env: RenderContext} $context */
147147
public function renderLink(array $context, string $url, string|null $anchor = null): string
148148
{
149-
return $this->getRenderContext($context)->relativeDocUrl($url, $anchor);
149+
return $this->getRenderContext($context)->generateCanonicalOutputUrl($url, $anchor);
150150
}
151151

152152
private function copyAsset(

packages/guides/src/UrlGenerator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ public function absoluteUrl(string $basePath, string $url): string
5151
* identifier to find the metadata for that file. Technically speaking, the canonical URL is the absolute URL
5252
* without the preceeding slash. But due to the many locations that this method is used; it will do its own
5353
* resolving.
54-
*
55-
* @todo simplify this method into the other methods or vice versa
5654
*/
5755
public function canonicalUrl(string $basePath, string $url): string
5856
{
@@ -86,6 +84,10 @@ public function createFileUrl(string $filename, string $outputFormat = 'html', s
8684
($anchor !== null ? '#' . $anchor : '');
8785
}
8886

87+
/**
88+
* Generate a canonical output URL with file extension, anchor and prefixed by
89+
* an absolute or relative path
90+
*/
8991
public function generateOutputUrlFromDocumentPath(
9092
string $currentDirectory,
9193
string $destinationPath,

packages/guides/src/UrlGeneratorInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public function absoluteUrl(string $basePath, string $url): string;
2121
* identifier to find the metadata for that file. Technically speaking, the canonical URL is the absolute URL
2222
* without the preceeding slash. But due to the many locations that this method is used; it will do its own
2323
* resolving.
24-
*
25-
* @todo simplify this method into the other methods or vice versa
2624
*/
2725
public function canonicalUrl(string $basePath, string $url): string;
2826

@@ -31,6 +29,10 @@ public function canonicalUrl(string $basePath, string $url): string;
3129
*/
3230
public function createFileUrl(string $filename, string $outputFormat = 'html', string|null $anchor = null): string;
3331

32+
/**
33+
* Generate a canonical output URL with file extension, anchor and prefixed by
34+
* an absolute or relative path
35+
*/
3436
public function generateOutputUrlFromDocumentPath(
3537
string $currentDirectory,
3638
string $destinationPath,

packages/guides/tests/unit/RenderContextTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testRelativeDocUrl(
4343
$projectNode,
4444
);
4545

46-
self::assertSame($result, $context->relativeDocUrl($linkedDocument, $anchor));
46+
self::assertSame($result, $context->generateCanonicalOutputUrl($linkedDocument, $anchor));
4747
}
4848

4949
/** @return string[][] */

0 commit comments

Comments
 (0)