mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
BUGFIX: Resolve navigation sorting using natural sort
This commit is contained in:
parent
a069dbd9d9
commit
6ba14bed75
@ -384,7 +384,8 @@ class DocumentationParser {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the children from a given module. Used for building the tree of the page
|
* Return the children from a given module sorted by Title using natural ordering.
|
||||||
|
* It is used for building the tree of the page.
|
||||||
*
|
*
|
||||||
* @param String module name
|
* @param String module name
|
||||||
*
|
*
|
||||||
@ -393,6 +394,7 @@ class DocumentationParser {
|
|||||||
public static function get_pages_from_folder($folder) {
|
public static function get_pages_from_folder($folder) {
|
||||||
$handle = opendir($folder);
|
$handle = opendir($folder);
|
||||||
$output = new DataObjectSet();
|
$output = new DataObjectSet();
|
||||||
|
$files = array();
|
||||||
|
|
||||||
if($handle) {
|
if($handle) {
|
||||||
$extensions = DocumentationService::get_valid_extensions();
|
$extensions = DocumentationService::get_valid_extensions();
|
||||||
@ -400,6 +402,13 @@ class DocumentationParser {
|
|||||||
|
|
||||||
while (false !== ($file = readdir($handle))) {
|
while (false !== ($file = readdir($handle))) {
|
||||||
if(!in_array($file, $ignore)) {
|
if(!in_array($file, $ignore)) {
|
||||||
|
$files[] = $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
natsort($files);
|
||||||
|
|
||||||
|
foreach($files as $file) {
|
||||||
$file = strtolower($file);
|
$file = strtolower($file);
|
||||||
|
|
||||||
$clean = ($pos = strrpos($file, '.')) ? substr($file, 0, $pos) : $file;
|
$clean = ($pos = strrpos($file, '.')) ? substr($file, 0, $pos) : $file;
|
||||||
@ -411,7 +420,6 @@ class DocumentationParser {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
@ -211,6 +211,14 @@ class DocumentationParserTest extends SapphireTest {
|
|||||||
$this->assertContains('subfolder', $pages->column('Filename'), 'Foldername');
|
$this->assertContains('subfolder', $pages->column('Filename'), 'Foldername');
|
||||||
$this->assertContains('test', $pages->column('Filename'), 'Filename');
|
$this->assertContains('test', $pages->column('Filename'), 'Filename');
|
||||||
$this->assertNotContains('_images', $pages->column('Filename'), 'Ignored files');
|
$this->assertNotContains('_images', $pages->column('Filename'), 'Ignored files');
|
||||||
|
|
||||||
|
// test the order of pages
|
||||||
|
$pages = DocumentationParser::get_pages_from_folder(BASE_PATH . '/sapphiredocs/tests/docs/en/sort');
|
||||||
|
$this->assertEquals(
|
||||||
|
array('1 basic', '2 intermediate', '3 advanced', '10 some page', '21 another page'),
|
||||||
|
$pages->column('Title')
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
0
tests/docs/en/sort/1-basic.md
Normal file
0
tests/docs/en/sort/1-basic.md
Normal file
0
tests/docs/en/sort/10-some-page.md
Normal file
0
tests/docs/en/sort/10-some-page.md
Normal file
0
tests/docs/en/sort/2-intermediate.md
Normal file
0
tests/docs/en/sort/2-intermediate.md
Normal file
0
tests/docs/en/sort/21-another-page.md
Normal file
0
tests/docs/en/sort/21-another-page.md
Normal file
0
tests/docs/en/sort/3-advanced.md
Normal file
0
tests/docs/en/sort/3-advanced.md
Normal file
Loading…
Reference in New Issue
Block a user