Update lede on new posts as user types

This commit is contained in:
Angelo Stavrow 2020-11-06 14:39:46 -05:00
parent 00bd18463e
commit 2d911cf0d6
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -44,7 +44,6 @@ private extension PostListModel {
return strippedString
}
func stripHeadingOctothorpes(from string: String) -> String {
let newLines = CharacterSet.newlines
var processedComponents: [String] = []
@ -102,19 +101,21 @@ private extension PostListModel {
func extractLede(from string: String) -> String {
let terminatingCharacters = CharacterSet(charactersIn: ".。?").union(.newlines)
var lede: String
var lede: String = ""
let sentences = string.components(separatedBy: terminatingCharacters)
let firstSentence = sentences.filter { !$0.isEmpty }[0]
if firstSentence == string {
let endOfStringIndex = string.lastIndex(of: " ")
lede = String(string[..<(endOfStringIndex ?? string.index(string.endIndex, offsetBy: -2))]) + ""
} else {
lede = firstSentence
if let firstSentence = sentences.filter({ !$0.isEmpty }).first {
if firstSentence == string {
if let endOfStringIndex = string.lastIndex(of: " ") {
lede = String(string[..<(endOfStringIndex )]) + ""
} else {
lede = String(string[..<string.endIndex])
}
} else {
lede = firstSentence
}
}
return lede
}
}