Add support for + at the beginning, fixes #18
This commit is contained in:
parent
d898eb6edf
commit
d1c7b27563
@ -10,6 +10,23 @@ if you wish to have one defined all you need to do is add an `index.md` file to
|
||||
For example, `/docs/02_Examples` has a landing page for that section since there exists a `/docs/02_Examples/index.md` file.
|
||||
|
||||
## Sorting
|
||||
To sort your files and folders in a specific way, you can prefix them with a number and underscore, e.g. `/docs/01_Hello_World.md` and `/docs/05_Features.md` This will list *Hello World* before *Features*, overriding the default alpha-numeric sorting. The numbers will be stripped out of the navigation and urls. For the file `6 Ways to Get Rich`, you can use `/docs/_6_Ways_to_Get_Rich.md`
|
||||
|
||||
You might also wish to stick certain links to the bottom of a page. You can do so by appending a '-' to the start of the filename, e.g. a new file `/docs/-Contact_Us.md` will always appear at the bottom of the current list. Weights can also be added to further sort the bottom entries. e.g. `/docs/-01_Coming.md` will appear before `/docs/-02_Soon.md` but both will only appear after all positive or non-weighted files.
|
||||
To sort your files and folders in a specific way, you can prefix them with a number and underscore, e.g. `/docs/01_Hello_World.md` and `/docs/05_Features.md`.
|
||||
This will list *Hello World* before *Features*, overriding the default alpha-numeric sorting.
|
||||
The numbers will be stripped out of the navigation and urls. For the file `6 Ways to Get Rich`, you can use `/docs/_6_Ways_to_Get_Rich.md`
|
||||
|
||||
You might also wish to stick certain links to the bottom of a page.
|
||||
You can do so by prefixing the file name with a '-', e.g. a new file `/docs/-Contact_Us.md` will always appear at the bottom of the current list.
|
||||
Weights can also be added to further sort the bottom entries. e.g. `/docs/-01_Coming.md` will appear before `/docs/-02_Soon.md` but both will only appear after all positive or non-weighted files.
|
||||
|
||||
It works the same for files prefixed with `+`.
|
||||
|
||||
Page order priorities are like this:
|
||||
|
||||
- `+` in front of the filename and numbers in front
|
||||
- `+` in front of the filename
|
||||
- The index page
|
||||
- Numbers in the front
|
||||
- Pages without prefix
|
||||
- `-` in front of the filename and numbers in front
|
||||
- `-` in front of the filename
|
||||
|
@ -136,7 +136,7 @@ class Builder
|
||||
*/
|
||||
public static function removeSortingInformations($filename)
|
||||
{
|
||||
preg_match('/^-?[0-9]*_?(.*)/', $filename, $matches);
|
||||
preg_match('/^[-+]?[0-9]*_?(.*)/', $filename, $matches);
|
||||
|
||||
// Remove the numeric part
|
||||
// of the filename, only if
|
||||
|
@ -15,6 +15,8 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
|
||||
{
|
||||
// Separate the values into buckets to sort them separately
|
||||
$buckets = [
|
||||
'up_numeric' => [],
|
||||
'up' => [],
|
||||
'index' => [],
|
||||
'numeric' => [],
|
||||
'normal' => [],
|
||||
@ -41,6 +43,17 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($name[0] == '+') {
|
||||
if (is_numeric($name[1])) {
|
||||
$exploded = explode('_', $name);
|
||||
$buckets['up_numeric'][abs(substr($exploded[0], 1))][$key] = $entry;
|
||||
continue;
|
||||
}
|
||||
|
||||
$buckets['up'][$key] = $entry;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_numeric($name[0])) {
|
||||
$exploded = explode('_', $name);
|
||||
$buckets['numeric'][abs($exploded[0])][$key] = $entry;
|
||||
@ -52,7 +65,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate
|
||||
|
||||
$final = [];
|
||||
foreach ($buckets as $name => $bucket) {
|
||||
if ($name == 'numeric' || $name == 'down_numeric') {
|
||||
if (substr($name, -7) == 'numeric') {
|
||||
ksort($bucket);
|
||||
foreach ($bucket as $sub_bucket) {
|
||||
$final = $this->sortBucket($sub_bucket, $final);
|
||||
|
@ -10,6 +10,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
return [
|
||||
['01_before', 'before'],
|
||||
['-Down', 'Down'],
|
||||
['+Up', 'Up'],
|
||||
['01_numeric', 'numeric'],
|
||||
['01_A_File', 'A_File'],
|
||||
['A_File', 'A_File'],
|
||||
@ -20,6 +21,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
['API_Calls', 'API_Calls'],
|
||||
['200_Something_Else-Cool', 'Something_Else-Cool'],
|
||||
['_5_Ways_to_Be_Happy', '5_Ways_to_Be_Happy'],
|
||||
['+02_Soon', 'Soon'],
|
||||
['Before_but_after', 'Before_but_after'],
|
||||
['Continuing', 'Continuing'],
|
||||
['01_GitHub_Flavored_Markdown', 'GitHub_Flavored_Markdown'],
|
||||
|
@ -15,6 +15,7 @@ class DirectoryTest extends \PHPUnit_Framework_TestCase
|
||||
[['01_numeric', '01_before'], ['01_before', '01_numeric']],
|
||||
[['A_File', '01_A_File'], ['01_A_File', 'A_File']],
|
||||
[['A_File', '01_Continuing', '-01_Coming', '-02_Soon'], ['01_Continuing', 'A_File', '-01_Coming', '-02_Soon']],
|
||||
[['+A_File', '01_Continuing', '+01_Coming', '-02_Soon'], ['+01_Coming', '+A_File', '01_Continuing', '-02_Soon']],
|
||||
[['01_Getting_Started', 'API_Calls', '200_Something_Else-Cool', '_5_Ways_to_Be_Happy'], ['01_Getting_Started', '200_Something_Else-Cool', '_5_Ways_to_Be_Happy', 'API_Calls']],
|
||||
[['01_Getting_Started', 'API_Calls', 'index', '200_Something_Else-Cool', '_5_Ways_to_Be_Happy'], ['index', '01_Getting_Started', '200_Something_Else-Cool', '_5_Ways_to_Be_Happy', 'API_Calls']],
|
||||
[['Before_but_after', 'A_File', 'Continuing'], ['A_File', 'Before_but_after', 'Continuing']],
|
||||
|
Loading…
x
Reference in New Issue
Block a user