Skip to content

Commit 4bdf378

Browse files
committed
Revert the addition of excerpts
1 parent 30fc85f commit 4bdf378

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

Modules/Sources/WordPressShared/Utility/GutenbergExcerptGenerator.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ public struct GutenbergExcerptGenerator {
1919
.replacingOccurrences(of: "<br\\s*/?>", with: " ", options: .regularExpression)
2020

2121
let range = NSRange(rawText.startIndex..., in: rawText)
22-
var text = (regex?.stringByReplacingMatches(in: rawText, options: [], range: range, withTemplate: "") ?? rawText)
22+
let text = (regex?.stringByReplacingMatches(in: rawText, options: [], range: range, withTemplate: "") ?? rawText)
2323
.stringByDecodingXMLCharacters()
2424
.trimmingCharacters(in: .whitespacesAndNewlines)
2525

26-
if text.count > maxLength {
27-
let truncated = String(text.prefix(maxLength))
28-
text = truncated.lastIndex(of: " ").map { String(truncated[..<$0]) } ?? truncated
26+
// Truncate if needed
27+
if text.count <= maxLength {
28+
return text
2929
}
3030

31-
if text.hasSuffix(".") {
32-
text = String(text.dropLast())
31+
let truncated = String(text.prefix(maxLength))
32+
if let lastSpace = truncated.lastIndex(of: " ") {
33+
return String(truncated[..<lastSpace]) + ""
3334
}
34-
return text + ""
35+
return truncated + ""
3536
}
3637
}

Modules/Tests/WordPressSharedTests/GutenbergExcerptGeneratorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ struct GutenbergPostExcerptGeneratorTests {
3737

3838
let summary = GutenbergExcerptGenerator.firstParagraph(from: content, maxLength: 150)
3939
print(summary)
40-
#expect(summary == "Yes, look behind in remembrance and with gratitude")
40+
#expect(summary == "Yes, look behind in remembrance and with gratitude.")
4141
}
4242
}

0 commit comments

Comments
 (0)