longform: add estimated read time to longform preview

Display estimated reading time in minutes alongside word count for longform
articles. Uses standard 200 words per minute reading rate calculation.

Closes: https://github.com/damus-io/damus/issues/3492
Changelog-Added: Added estimated read time to longform preview
Signed-off-by: alltheseas
This commit is contained in:
alltheseas
2026-01-04 18:27:42 -06:00
committed by Daniel D’Aquino
parent 0233f2ae48
commit e8e2653316
3 changed files with 36 additions and 2 deletions

View File

@@ -381,6 +381,11 @@ struct LongformContent {
let markdown: MarkdownContent
let words: Int
/// Estimated reading time in minutes, based on average reading speed of 200 words per minute.
var estimatedReadTimeMinutes: Int {
return max(1, words / 200)
}
init(_ markdown: String) {
// Pre-process markdown to ensure images are block-level (have blank lines around them)
// This prevents images from being parsed as inline within text paragraphs

View File

@@ -35,10 +35,17 @@ struct LongformPreviewBody: View {
self._artifacts = ObservedObject(wrappedValue: state.events.get_cache_data(ev.id).artifacts_model)
}
/// Formats word count for display.
func Words(_ words: Int) -> Text {
let wordCount = pluralizedString(key: "word_count", count: words)
return Text(wordCount)
}
/// Formats estimated read time for display.
func ReadTime(_ minutes: Int) -> Text {
let readTime = pluralizedString(key: "read_time", count: minutes)
return Text(readTime)
}
var truncate: Bool {
return options.contains(.truncate_content)
@@ -161,8 +168,14 @@ struct LongformPreviewBody: View {
if case .loaded(let arts) = artifacts.state,
case .longform(let longform) = arts
{
Words(longform.words).font(.footnote)
.padding([.horizontal, .bottom], 10)
HStack(spacing: 8) {
ReadTime(longform.estimatedReadTimeMinutes)
Text("·")
Words(longform.words)
}
.font(.footnote)
.foregroundColor(.gray)
.padding([.horizontal, .bottom], 10)
}
}
.frame(maxWidth: .infinity, alignment: .leading)

View File

@@ -386,6 +386,22 @@
<string>%d Words</string>
</dict>
</dict>
<key>read_time</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@MINUTES@</string>
<key>MINUTES</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%d min read</string>
<key>other</key>
<string>%d min read</string>
</dict>
</dict>
<key>zap_notification_no_message</key>
<dict>
<key>NSStringLocalizedFormatKey</key>