mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Don't return more than the first line on short titleless posts
This commit is contained in:
parent
d989709319
commit
cd6f8adbbb
@ -96,9 +96,7 @@ private extension PostListModel {
|
||||
}
|
||||
|
||||
func extractLede(from string: String) -> String {
|
||||
if string.utf16.count <= 80 {
|
||||
return string
|
||||
}
|
||||
if string.isEmpty { return string }
|
||||
|
||||
let truncatedString = string.prefix(80)
|
||||
let terminatingCharacters = CharacterSet(charactersIn: ".。?").union(.newlines)
|
||||
@ -109,13 +107,13 @@ private extension PostListModel {
|
||||
let sentences = truncatedString.components(separatedBy: terminatingCharacters)
|
||||
let firstSentence = sentences.filter { !$0.isEmpty }[0]
|
||||
|
||||
if firstSentence == truncatedString {
|
||||
if firstSentence == truncatedString && string.utf16.count > 80 {
|
||||
let endOfStringIndex = truncatedString.lastIndex(of: " ")
|
||||
lede = String(
|
||||
truncatedString[..<(endOfStringIndex ?? truncatedString.index(truncatedString.endIndex, offsetBy: -2))]
|
||||
) + "…"
|
||||
} else {
|
||||
lede = String(truncatedString[...firstSentence.endIndex])
|
||||
lede = String(truncatedString[..<firstSentence.endIndex])
|
||||
}
|
||||
|
||||
return lede
|
||||
|
Loading…
Reference in New Issue
Block a user