Skip to content

Commit

Permalink
Fix natural sort when > 100 pages (#1564)
Browse files Browse the repository at this point in the history
* Fix natural sort when > 100 pages

* Revert manual and default sort type

* Only check prefix numbers
  • Loading branch information
w00fz authored and rhukster committed Jul 12, 2017
1 parent 4332dd0 commit 287a511
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions system/src/Grav/Common/Page/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,12 @@ protected function buildSort($path, array $pages, $order_by = 'default', $manual
$locale = setlocale(LC_COLLATE, 0); //`setlocale` with a 0 param returns the current locale set
$col = Collator::create($locale);
if ($col) {
if (($sort_flags & SORT_NATURAL) === SORT_NATURAL) {
$list = preg_replace_callback('~([0-9]+)\.~', function($number) {
return sprintf('%032d', $number);
}, $list);
}

$col->asort($list, $sort_flags);
} else {
asort($list, $sort_flags);
Expand Down

0 comments on commit 287a511

Please sign in to comment.