mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00:00
ENHANCEMENT: if a folder is missing an index.md file load the first file as a failback
This commit is contained in:
parent
fc8ab96c51
commit
2a7b7ee83d
@ -393,11 +393,8 @@ class DocumentationService {
|
|||||||
$base = rtrim($base, '/') .'/';
|
$base = rtrim($base, '/') .'/';
|
||||||
|
|
||||||
while (false !== ($file = readdir($handle))) {
|
while (false !== ($file = readdir($handle))) {
|
||||||
|
|
||||||
if(in_array($file, DocumentationService::get_valid_extensions())) continue;
|
if(in_array($file, DocumentationService::get_valid_extensions())) continue;
|
||||||
|
|
||||||
if(!$firstFile && !is_dir($base . $file)) $firstFile = $file;
|
|
||||||
|
|
||||||
$formatted = strtolower($file);
|
$formatted = strtolower($file);
|
||||||
|
|
||||||
// if the name has a . then take the substr
|
// if the name has a . then take the substr
|
||||||
@ -409,6 +406,9 @@ class DocumentationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save this file as a backup if we don't have one to fail back to
|
||||||
|
if(!$firstFile && !is_dir($base . $file)) $firstFile = $file;
|
||||||
|
|
||||||
// the folder is the one that we are looking for.
|
// the folder is the one that we are looking for.
|
||||||
if(strtolower($name) == strtolower($formatted)) {
|
if(strtolower($name) == strtolower($formatted)) {
|
||||||
|
|
||||||
@ -439,13 +439,15 @@ class DocumentationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if goal has not been found and the index.md file does not exist then the next
|
||||||
|
// option is to pick the first file in the folder
|
||||||
|
return $base . ltrim($firstFile, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
|
|
||||||
// if goal has not been found and the index.md file does not exist then the next
|
return false;
|
||||||
// option is to pick the first file in the folder
|
|
||||||
return $base . ltrim($file, '/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -379,6 +379,7 @@ class DocumentationViewer extends Controller {
|
|||||||
|
|
||||||
$page = new DocumentationPage();
|
$page = new DocumentationPage();
|
||||||
$page->setRelativePath($relativeFilePath);
|
$page->setRelativePath($relativeFilePath);
|
||||||
|
|
||||||
$page->setEntity($module);
|
$page->setEntity($module);
|
||||||
$page->setLang($this->Lang);
|
$page->setLang($this->Lang);
|
||||||
$page->setVersion($this->Version);
|
$page->setVersion($this->Version);
|
||||||
@ -409,7 +410,6 @@ class DocumentationViewer extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$page->LinkingMode = 'link';
|
$page->LinkingMode = 'link';
|
||||||
|
|
||||||
$page->Children = $this->_getModulePagesNested($page, $module);
|
$page->Children = $this->_getModulePagesNested($page, $module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -423,6 +423,10 @@ class DocumentationViewer extends Controller {
|
|||||||
/**
|
/**
|
||||||
* Get the module pages under a given page. Recursive call for {@link getModulePages()}
|
* Get the module pages under a given page. Recursive call for {@link getModulePages()}
|
||||||
*
|
*
|
||||||
|
* @todo Need to rethink how to support pages which are pulling content from their children
|
||||||
|
* i.e if a folder doesn't have index.md then it will load the first file in the folder
|
||||||
|
* however it doesn't yet pass the highlighting to it.
|
||||||
|
*
|
||||||
* @param ArrayData CurrentPage
|
* @param ArrayData CurrentPage
|
||||||
* @param DocumentationEntity
|
* @param DocumentationEntity
|
||||||
* @param int Depth of page in the tree
|
* @param int Depth of page in the tree
|
||||||
@ -440,8 +444,13 @@ class DocumentationViewer extends Controller {
|
|||||||
|
|
||||||
// its either in this section or is the actual link
|
// its either in this section or is the actual link
|
||||||
$page->LinkingMode = (isset($this->Remaining[$level + 1])) ? 'section' : 'current';
|
$page->LinkingMode = (isset($this->Remaining[$level + 1])) ? 'section' : 'current';
|
||||||
|
|
||||||
if(is_dir($page->getPath())) {
|
$relativePath = Controller::join_links(
|
||||||
|
$module->getPath($page->getVersion(), $page->getLang()),
|
||||||
|
$page->getRelativePath()
|
||||||
|
);
|
||||||
|
|
||||||
|
if(is_dir($relativePath)) {
|
||||||
$children = DocumentationService::get_pages_from_folder($module, $page->getRelativePath(), false);
|
$children = DocumentationService::get_pages_from_folder($module, $page->getRelativePath(), false);
|
||||||
|
|
||||||
$segments = array();
|
$segments = array();
|
||||||
@ -455,7 +464,7 @@ class DocumentationViewer extends Controller {
|
|||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$child->LinkingMode = 'link';
|
$child->LinkingMode = 'link';
|
||||||
$child->Children = $this->_getModulePagesNested($child, $module, $level + 1);
|
$child->Children = $this->_getModulePagesNested($child, $module, $level + 1);
|
||||||
}
|
}
|
||||||
|
@ -57,9 +57,10 @@ class DocumentationServiceTest extends SapphireTest {
|
|||||||
// second level
|
// second level
|
||||||
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subpage'));
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subpage'));
|
||||||
$this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subpage.md", $path);
|
$this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subpage.md", $path);
|
||||||
|
|
||||||
|
// subsubfolder has no index file. It should fail through to the first file
|
||||||
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder'));
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder'));
|
||||||
$this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/", $path);
|
$this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path);
|
||||||
|
|
||||||
// third level
|
// third level
|
||||||
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage'));
|
$path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user