diff --git a/code/DocumentationParser.php b/code/DocumentationParser.php index 40079f0..e915123 100644 --- a/code/DocumentationParser.php +++ b/code/DocumentationParser.php @@ -320,7 +320,7 @@ class DocumentationParser { $name = strtolower(array_shift($goal)); if(!$name) $name = 'index'; - + if($handle) { $extensions = DocumentationService::get_valid_extensions(); @@ -331,11 +331,10 @@ class DocumentationParser { // if the name has a . then take the substr $formatted = ($pos = strrpos($formatted, '.')) ? substr($formatted, 0, $pos) : $formatted; - $name = ($dot = strrpos($formatted, '.')) ? substr($name, 0, $dot) : $name; - - // the folder is the one that we are looking for. - if($name == $formatted) { + $name = ($dot = strrpos($name, '.')) ? substr($name, 0, $dot) : $name; + // the folder is the one that we are looking for. + if(strtolower($name) == strtolower($formatted)) { if(is_dir($base . $file)) { // if this is a directory check that there is any more states to get // to in the goal. If none then what we want is the 'index.md' file @@ -350,13 +349,13 @@ class DocumentationParser { else { // goal state. End of recursion $result = $base .'/'. $file; - + return $result; } } } } - + closedir($handle); } diff --git a/code/DocumentationViewer.php b/code/DocumentationViewer.php index 38d614b..ad22a74 100755 --- a/code/DocumentationViewer.php +++ b/code/DocumentationViewer.php @@ -354,6 +354,7 @@ class DocumentationViewer extends Controller { if(!$module) return false; $absFilepath = DocumentationParser::find_page($module->getPath(), $this->Remaining); + if($absFilepath) { $relativeFilePath = str_replace($module->getPath(), '', $absFilepath); @@ -382,6 +383,12 @@ class DocumentationViewer extends Controller { if($pages) { foreach($pages as $page) { + if(strtolower($page->Title) == "index") { + $pages->remove($page); + + continue; + } + $linkParts = array(); // don't include the 'index in the url @@ -426,6 +433,12 @@ class DocumentationViewer extends Controller { } foreach($children as $child) { + if(strtolower($child->Title) == "index") { + $children->remove($child); + + continue; + } + $child->Link = $this->Link(array_merge($segments, array($child->Filename))); $child->LinkingMode = 'link'; $child->Children = $this->_getModulePagesNested($child, $level + 1); diff --git a/tests/DocumentationViewerTests.php b/tests/DocumentationViewerTests.php index 3616695..f51112b 100644 --- a/tests/DocumentationViewerTests.php +++ b/tests/DocumentationViewerTests.php @@ -127,22 +127,23 @@ class DocumentationViewerTests extends FunctionalTest { $response = $v->handleRequest(new SS_HTTPRequest('GET', '2.4/en/DocumentationViewerTests/subfolder/')); $pages = $v->getModulePages(); $this->assertEquals( - array('index', 'sort', 'subfolder', 'test'), + array('sort', 'subfolder', 'test'), $pages->column('Filename') ); $this->assertEquals( - array('link', 'link','current', 'link'), + array('link','current', 'link'), $pages->column('LinkingMode') ); $links = $pages->column('Link'); - $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/', $links[0]); - $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/sort/', $links[1]); - $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/subfolder/', $links[2]); - $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/test/', $links[3]); + + $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/sort/', $links[0]); + $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/subfolder/', $links[1]); + $this->assertStringEndsWith('2.4/en/DocumentationViewerTests/test/', $links[2]); // Children $pagesArr = $pages->toArray(); - $child1 = $pagesArr[0]; + + $child1 = $pagesArr[1]; $this->assertFalse($child1->Children);