mirror of
https://github.com/symfony/ai.git
synced 2026-03-23 23:42:18 +01:00
[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:
@@ -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';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
Components
|
||||
==========
|
||||
|
||||
This section describes the available components.
|
||||
@@ -0,0 +1,9 @@
|
||||
Main Index
|
||||
==========
|
||||
|
||||
Welcome to the documentation.
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
components/
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user