Don't sort pages when a unknown sort method is specified

Specifying a custom sort method usually means that all pages are sort by a plugin, so Pico's default alphabetical order is overwritten anyway. Letting Pico sort the pages first and discarding the result is burned CPU time...
This commit is contained in:
Daniel Rudolf 2016-12-06 19:47:37 +01:00
parent b493ebdb84
commit 82c6dd9795
No known key found for this signature in database
GPG key ID: A061F02CD8DE4538

View file

@ -1279,6 +1279,12 @@ class Pico
{
// sort pages
$order = $this->getConfig('pages_order');
$orderBy = $this->getConfig('pages_order_by');
if (($orderBy !== 'date') && ($orderBy !== 'alpha')) {
return;
}
$alphaSortClosure = function ($a, $b) use ($order) {
$aSortKey = (basename($a['id']) === 'index') ? dirname($a['id']) : $a['id'];
$bSortKey = (basename($b['id']) === 'index') ? dirname($b['id']) : $b['id'];
@ -1287,7 +1293,7 @@ class Pico
return $cmp * (($order === 'desc') ? -1 : 1);
};
if ($this->getConfig('pages_order_by') === 'date') {
if ($orderBy === 'date') {
// sort by date
uasort($this->pages, function ($a, $b) use ($alphaSortClosure, $order) {
if (empty($a['time']) || empty($b['time'])) {