diff --git a/src/store/src/Document/Loader/RstToctreeLoader.php b/src/store/src/Document/Loader/RstToctreeLoader.php index 4a17f8ca..d14ce324 100644 --- a/src/store/src/Document/Loader/RstToctreeLoader.php +++ b/src/store/src/Document/Loader/RstToctreeLoader.php @@ -116,6 +116,8 @@ final class RstToctreeLoader implements LoaderInterface if (str_ends_with($entryPath, '.rst')) { $pattern = $dir.'/'.$entryPath; + } elseif (str_ends_with($entryPath, '/')) { + $pattern = $dir.'/'.$entryPath.'index.rst'; } else { $pattern = $dir.'/'.$entryPath.'.rst'; } diff --git a/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/components/index.rst b/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/components/index.rst new file mode 100644 index 00000000..8dfbbaa2 --- /dev/null +++ b/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/components/index.rst @@ -0,0 +1,4 @@ +Components +========== + +This section describes the available components. diff --git a/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/index.rst b/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/index.rst new file mode 100644 index 00000000..6b4d2fb4 --- /dev/null +++ b/src/store/tests/Document/Loader/Fixtures/rst/with_trailing_slash_toctree/index.rst @@ -0,0 +1,9 @@ +Main Index +========== + +Welcome to the documentation. + +.. toctree:: + :hidden: + + components/ diff --git a/src/store/tests/Document/Loader/RstToctreeLoaderTest.php b/src/store/tests/Document/Loader/RstToctreeLoaderTest.php index c91a50ab..4738e558 100644 --- a/src/store/tests/Document/Loader/RstToctreeLoaderTest.php +++ b/src/store/tests/Document/Loader/RstToctreeLoaderTest.php @@ -221,6 +221,20 @@ final class RstToctreeLoaderTest extends TestCase $this->assertCount(1, $alphaDocs); } + public function testLoadToctreeWithTrailingSlashResolvesToIndex() + { + $loader = new RstToctreeLoader(); + $documents = iterator_to_array($loader->load($this->fixturesDir.'/with_trailing_slash_toctree/index.rst'), false); + + $titles = array_map( + static fn (EmbeddableDocumentInterface $doc): string => $doc->getMetadata()->getTitle() ?? '', + $documents, + ); + + $this->assertContains('Main Index', $titles); + $this->assertContains('Components', $titles); + } + public function testLoadToctreeThrowsForMissingEntry() { $tempDir = sys_get_temp_dir().'/rst_missing_test_'.uniqid();