Skip to content

Commit 8c76e56

Browse files
committed
[FEATURE] Enable relative menu entries
resolves #821
1 parent 91c5377 commit 8c76e56

File tree

13 files changed

+280
-3
lines changed

13 files changed

+280
-3
lines changed

packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/InternalMenuEntryNodeTransformer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use phpDocumentor\Guides\Nodes\Menu\MenuNode;
2020
use phpDocumentor\Guides\Nodes\Menu\TocNode;
2121
use phpDocumentor\Guides\Nodes\Node;
22+
use phpDocumentor\Guides\ReferenceResolvers\DocumentNameResolverInterface;
23+
use Psr\Log\LoggerInterface;
2224

2325
use function array_pop;
2426
use function assert;
@@ -34,6 +36,13 @@ final class InternalMenuEntryNodeTransformer extends AbstractMenuEntryNodeTransf
3436
// Setting a default level prevents PHP errors in case of circular references
3537
private const DEFAULT_MAX_LEVELS = 10;
3638

39+
public function __construct(
40+
LoggerInterface $logger,
41+
private readonly DocumentNameResolverInterface $documentNameResolver,
42+
) {
43+
parent::__construct($logger);
44+
}
45+
3746
public function supports(Node $node): bool
3847
{
3948
return $node instanceof InternalMenuEntryNode;
@@ -81,7 +90,7 @@ protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNo
8190
return [];
8291
}
8392

84-
private static function matches(string $actualFile, InternalMenuEntryNode $parsedMenuEntryNode, string $currentFile): bool
93+
private function matches(string $actualFile, InternalMenuEntryNode $parsedMenuEntryNode, string $currentFile): bool
8594
{
8695
$expectedFile = $parsedMenuEntryNode->getUrl();
8796
if (self::isAbsoluteFile($expectedFile)) {
@@ -90,8 +99,9 @@ private static function matches(string $actualFile, InternalMenuEntryNode $parse
9099

91100
$current = explode('/', $currentFile);
92101
array_pop($current);
93-
$current[] = $expectedFile;
94-
$absoluteExpectedFile = implode('/', $current);
102+
103+
104+
$absoluteExpectedFile = $this->documentNameResolver->canonicalUrl(implode('/', $current), $expectedFile);
95105

96106
return $absoluteExpectedFile === $actualFile;
97107
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<!DOCTYPE html>
2+
<html class="no-js" lang="en">
3+
<head>
4+
<title>Document Title - Bootstrap Theme</title>
5+
<!-- Required meta tags -->
6+
<meta charset="utf-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
9+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
10+
</head>
11+
<body>
12+
<header class="">
13+
14+
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
15+
<div class="container">
16+
17+
<a class="navbar-brand" href="#">Navbar</a>
18+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
19+
<span class="navbar-toggler-icon"></span>
20+
</button>
21+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
22+
23+
24+
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
25+
<li class="nav-item">
26+
<a href="someDirectory/index.html" class="nav-link" >
27+
Some Page
28+
</a>
29+
</li> <ul class="level-">
30+
<li class="nav-item"><a href="someDirectory/index.html"
31+
class="nav-link" >
32+
Some Page
33+
</a></li></ul>
34+
</ul>
35+
36+
37+
</div>
38+
</div>
39+
</nav>
40+
</header>
41+
<main id="main-content">
42+
<div class="container">
43+
<div class="container">
44+
<div class="row">
45+
<div class="col-lg-3">
46+
<nav class="nav flex-column">
47+
<ul class="menu-level-main">
48+
<li><a href="someDirectory/index.html"
49+
class="nav-link">
50+
Some Page
51+
</a>
52+
<ul class="level-1">
53+
<li><a href="levelup1.html"
54+
class="nav-link">
55+
Level up 1
56+
</a></li>
57+
<li><a href="someDirectory/anotherDirectory/index.html"
58+
class="nav-link">
59+
Another Page
60+
</a>
61+
<ul class="level-2">
62+
<li><a href="levelup2.html"
63+
class="nav-link">
64+
Level up 2
65+
</a></li>
66+
<li><a href="someDirectory/anotherDirectory/yetAnotherDirectory/index.html"
67+
class="nav-link">
68+
Yet Another Page
69+
</a>
70+
<ul class="level-3">
71+
<li><a href="levelup3.html"
72+
class="nav-link">
73+
Level up 3
74+
</a></li>
75+
<li><a href="someDirectory/anotherDirectory/yetAnotherDirectory/andYetAnotherDirectory/index.html"
76+
class="nav-link">
77+
And Yet Another Page
78+
</a>
79+
<ul class="level-4">
80+
<li><a href="levelup4.html"
81+
class="nav-link">
82+
Level up 4
83+
</a></li>
84+
</ul>
85+
</li>
86+
</ul>
87+
</li>
88+
</ul>
89+
</li>
90+
</ul>
91+
</li>
92+
</ul>
93+
94+
</nav>
95+
96+
97+
</div>
98+
<div class="col-lg-9">
99+
100+
<nav aria-label="breadcrumb">
101+
<ol class="breadcrumb">
102+
<li class="breadcrumb-item"><a href="#">Document Title</a></li>
103+
</ol>
104+
</nav>
105+
106+
<!-- content start -->
107+
108+
109+
<div class="section" id="document-title">
110+
<h1>Document Title</h1>
111+
112+
<p>Lorem Ipsum Dolor.</p>
113+
<div class="toc">
114+
<ul class="menu-level">
115+
<li class="toc-item"><a href="someDirectory/index.html#some-page">Some Page</a> <ul class="menu-level-1">
116+
<li class="toc-item"><a href="levelup1.html#level-up-1">Level up 1</a></li>
117+
118+
<li class="toc-item"><a href="someDirectory/anotherDirectory/index.html#another-page">Another Page</a> <ul class="menu-level-2">
119+
<li class="toc-item"><a href="levelup2.html#level-up-2">Level up 2</a></li>
120+
121+
<li class="toc-item"><a href="someDirectory/anotherDirectory/yetAnotherDirectory/index.html#yet-another-page">Yet Another Page</a> <ul class="menu-level-3">
122+
<li class="toc-item"><a href="levelup3.html#level-up-3">Level up 3</a></li>
123+
124+
<li class="toc-item"><a href="someDirectory/anotherDirectory/yetAnotherDirectory/andYetAnotherDirectory/index.html#and-yet-another-page">And Yet Another Page</a> <ul class="menu-level-4">
125+
<li class="toc-item"><a href="levelup4.html#level-up-4">Level up 4</a></li>
126+
127+
</ul></li>
128+
129+
</ul></li>
130+
131+
</ul></li>
132+
133+
</ul></li>
134+
135+
</ul>
136+
</div>
137+
138+
</div>
139+
140+
<!-- content end -->
141+
</div>
142+
</div>
143+
</div>
144+
</div>
145+
</main>
146+
<footer class="bg-primary text-light">
147+
<div class="container">
148+
<p>Generated by <a href="https://www.phpdoc.org/">phpDocumentor</a>.</p>
149+
</div>
150+
</footer>
151+
152+
<!-- Optional JavaScript; choose one of the two! -->
153+
154+
<!-- Option 1: Bootstrap Bundle with Popper -->
155+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
156+
157+
<!-- Option 2: Separate Popper and Bootstrap JS -->
158+
<!--
159+
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
160+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
161+
-->
162+
</body>
163+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<guides xmlns="https://www.phpdoc.org/guides"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd"
5+
theme="bootstrap"
6+
links-are-relative="true"
7+
>
8+
<extension class="phpDocumentor\Guides\Bootstrap"/>
9+
</guides>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. documentblock::
2+
:identifier: footer
3+
4+
Generated by `phpDocumentor <https://www.phpdoc.org/>`__.
5+
6+
.. role:: custom
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.. include:: /include.rst.txt
2+
3+
:project:
4+
Bootstrap Theme
5+
:version:
6+
1.0
7+
8+
==============
9+
Document Title
10+
==============
11+
12+
Lorem Ipsum Dolor.
13+
14+
.. toctree::
15+
:glob:
16+
:titlesonly:
17+
18+
*/index
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Level up 1
2+
==========
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Level up 2
2+
==========
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Level up 3
2+
==========
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Level up 4
2+
==========
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.. include:: /include.rst.txt
2+
3+
============
4+
Another Page
5+
============
6+
7+
Lorem Ipsum Dolor.
8+
9+
10+
.. toctree::
11+
:hidden:
12+
:glob:
13+
:titlesonly:
14+
15+
../../levelup2
16+
*/index

0 commit comments

Comments
 (0)