Consistent sorting of output

This commit is contained in:
Christoph Hagen
2025-01-27 07:56:36 +01:00
parent 09b1f48aea
commit 82c40cc080
6 changed files with 23 additions and 6 deletions

View File

@ -2,6 +2,8 @@ import Foundation
protocol DateItem {
var id: String { get }
var startDate: Date { get }
var hasEndDate: Bool { get }
@ -9,6 +11,18 @@ protocol DateItem {
var potentialEndDate: Date { get }
}
extension Sequence where Element: DateItem {
func sortedByStartDateAndId() -> [Element] {
sorted { (lhs, rhs) -> Bool in
if lhs.startDate == rhs.startDate {
return lhs.id < rhs.id
}
return lhs.startDate > rhs.startDate
}
}
}
extension DateItem {
var endDate: Date? {

View File

@ -24,8 +24,8 @@ final class LoadingContext {
func results() -> LoadingResult {
.init(
settings: settings ?? .default,
posts: posts.values.sorted(ascending: false) { $0.startDate },
pages: pages.values.sorted(ascending: false) { $0.startDate },
posts: posts.values.sortedByStartDateAndId(),
pages: pages.values.sortedByStartDateAndId(),
tags: tags.values.sorted(),
files: files.values.sorted { $0.id },
tagOverview: tagOverview,