Skip to content

Commit

Permalink
Merge pull request #489 from greg0ire/canonicalize-urls
Browse files Browse the repository at this point in the history
Canonicalize urls
  • Loading branch information
jaapio authored Jul 12, 2023
2 parents 0dd4015 + 6444b81 commit bca6ff6
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/contributions/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ Clone the mono repository
Run the tests
=============

The project comes with a Makefile that will run the tests and other
checks for you.
It relies on ``docker``, but you can run any make target natively by
using the ``PHP_BIN`` make variable.
For instance, to run the pre-commit checks, you can run::

make PHP_BIN=php pre-commit-test

Submit a Pull Request
=====================
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext): boo
return false;
}

$document = $renderContext->getProjectNode()->findDocumentEntry($node->getTargetReference());
$document = $renderContext->getProjectNode()->findDocumentEntry(
$renderContext->canonicalUrl($node->getTargetReference()),
);
if ($document === null) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/guides/src/RenderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getLink(string $name, bool $relative = true): string
return '';
}

public function canonicalUrl(string $url): string|null
public function canonicalUrl(string $url): string
{
return $this->urlGenerator->canonicalUrl($this->getDirName(), $url);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Integration/tests/docref/expected/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Root</title>

</head>
<body>
<div class="section" id="root">
<h1>Root</h1>

</div>

</body>
</html>
15 changes: 15 additions & 0 deletions tests/Integration/tests/docref/expected/subfolder/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Subfolder index</title>

</head>
<body>
<div class="section" id="subfolder-index">
<h1>Subfolder index</h1>

<p><a href="/index.html">Root</a></p>
</div>

</body>
</html>
3 changes: 3 additions & 0 deletions tests/Integration/tests/docref/input/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
====
Root
====
5 changes: 5 additions & 0 deletions tests/Integration/tests/docref/input/subfolder/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
===============
Subfolder index
===============

:doc:`../index`
10 changes: 10 additions & 0 deletions tests/Integration/tests/references/expected/subfolder/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>

</head>
<body>
<p><a href="/page.html">Page 1</a></p>
</body>
</html>
6 changes: 6 additions & 0 deletions tests/Integration/tests/references/input/subfolder/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
===============
Subfolder index
===============


:doc:`../page`

0 comments on commit bca6ff6

Please sign in to comment.