[Store] Fix RstToctreeLoader trailing-slash toctree entry resolution

Trailing-slash toctree entries like `components/` are valid Sphinx
syntax and resolve to `components/index.rst`. The loader now handles
this convention instead of producing the invalid path `components/.rst`.
This commit is contained in:
Johannes Wachter
2026-03-15 21:43:33 +01:00
parent 6a39e55e55
commit 1bd2a72eb0
4 changed files with 29 additions and 0 deletions

View File

@@ -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';
}

View File

@@ -0,0 +1,4 @@
Components
==========
This section describes the available components.

View File

@@ -0,0 +1,9 @@
Main Index
==========
Welcome to the documentation.
.. toctree::
:hidden:
components/

View File

@@ -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();