mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-03 18:56:14 +00:00
Sort by the displayed title text so untitled articles sort by their body excerpt.
This commit is contained in:
1 parent
597eab1549
commit
70c3ec8097
1 file changed
+11
-2
@@ -64,8 +64,8 @@ private extension ArticleSorter {
|
||||
|
||||
static func sortedByTitle(articles: [Article], sortDirection: ComparisonResult) -> [Article] {
|
||||
articles.sorted { article1, article2 in
|
||||
let title1 = article1.title ?? ""
|
||||
let title2 = article2.title ?? ""
|
||||
let title1 = sortableTitle(for: article1)
|
||||
let title2 = sortableTitle(for: article2)
|
||||
return switch title1.compare(title2, options: titleCompareOptions, range: nil, locale: .current) {
|
||||
case .orderedAscending: sortDirection == .orderedAscending
|
||||
case .orderedDescending: sortDirection != .orderedAscending
|
||||
@@ -74,6 +74,15 @@ private extension ArticleSorter {
|
||||
}
|
||||
}
|
||||
|
||||
/// The text the timeline shows as the title: the title, or the start of the body for an untitled article.
|
||||
static func sortableTitle(for article: Article) -> String {
|
||||
let title = ArticleStringFormatter.shared.truncatedTitle(article)
|
||||
if !title.isEmpty {
|
||||
return title
|
||||
}
|
||||
return ArticleStringFormatter.shared.truncatedSummary(article)
|
||||
}
|
||||
|
||||
/// Descending puts articles with the flag set on top.
|
||||
static func sortedByFlag(articles: [Article], sortDirection: ComparisonResult, flag: (Article) -> Bool) -> [Article] {
|
||||
articles.sorted { article1, article2 in
|
||||
|
||||
Reference in new issue
Block a user