Add configurable sorting order for items

This commit is contained in:
Ruben 2025-11-29 00:54:55 +01:00
parent 76697e4656
commit 77f97a3a5d

View file

@ -152,8 +152,14 @@ switch ($parsedPath['type']) {
]; ];
}, $subdirs)); }, $subdirs));
// Sort by date (newest first) if dates are present // Sort by date - check metadata for order preference
usort($items, fn($a, $b) => strcmp($b['date'] ?? '', $a['date'] ?? '')); $sortOrder = strtolower($metadata['order'] ?? 'descending');
if ($sortOrder === 'ascending') {
usort($items, fn($a, $b) => strcmp($a['date'] ?? '', $b['date'] ?? ''));
} else {
// Default: descending (newest first)
usort($items, fn($a, $b) => strcmp($b['date'] ?? '', $a['date'] ?? ''));
}
// Prepare all variables for base template // Prepare all variables for base template
$navigation = $ctx->navigation; $navigation = $ctx->navigation;