diff --git a/libs/Tree/Builder.php b/libs/Tree/Builder.php index 2defa09..b3587d5 100644 --- a/libs/Tree/Builder.php +++ b/libs/Tree/Builder.php @@ -75,10 +75,16 @@ class Builder } if ($file->isDir()) { - $new = new Directory($node, static::removeSortingInformations($file->getFilename()), $file); + $title = static::removeSortingInformations($file->getFilename()); + $new = new Directory($node, $title, $file); $new->setName(static::getName($file->getPathName())); $new->setTitle(str_replace('_', ' ', static::removeSortingInformations($new->getName()))); static::build($new, $ignore); + + $index = $new->getLocalIndexPage(); + if ($index && $index->getTitle() != $title) { + $new->setTitle($index->getTitle()); + } } else { static::createContent($node, $file); } diff --git a/libs/Tree/Directory.php b/libs/Tree/Directory.php index d3c6a1f..958f1d6 100644 --- a/libs/Tree/Directory.php +++ b/libs/Tree/Directory.php @@ -125,6 +125,16 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate return $this->parent->getConfig(); } + public function getLocalIndexPage() { + $index_key = $this->getConfig()['index_key']; + + if (isset($this->children[$index_key])) { + return $this->children[$index_key]; + } + + return false; + } + /** * @return Content|null */ @@ -132,8 +142,8 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate { $index_key = $this->getConfig()['index_key']; - if (isset($this->children[$index_key])) { - return $this->children[$index_key]; + if ($this->getLocalIndexPage()) { + return $this->getLocalIndexPage(); } if ($this->getConfig()->shouldInheritIndex() && $first_page = $this->seekFirstPage()) { diff --git a/tests/Tree/BuilderTest.php b/tests/Tree/BuilderTest.php index a034df5..d675925 100644 --- a/tests/Tree/BuilderTest.php +++ b/tests/Tree/BuilderTest.php @@ -171,4 +171,28 @@ class BuilderTest extends TestCase array_keys($tree->getEntries()) ); } + + public function testIndexFrontMatter() + { + $structure = [ + 'folder' => [ + 'index.md' => "---\ntitle: new Title\n---\nThe content", + 'Page.md' => 'another page', + 'Button.md' => 'another page' + ] + ]; + $root = vfsStream::setup('root', null, $structure); + + $config = new Config; + $config->setDocumentationDirectory($root->url()); + $config['valid_content_extensions'] = ['md']; + $config['mode'] = Daux::STATIC_MODE; + $config['index_key'] = 'index.html'; + + $tree = new Root($config); + Builder::build($tree, []); + + $this->assertTrue(array_key_exists('folder', $tree->getEntries())); + $this->assertEquals('new Title', $tree->getEntries()['folder']->getTitle()); + } }