From 31654c08cbee941b9e6e77342db915dffcbb4ee2 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Tue, 11 Apr 2023 19:31:22 +0200 Subject: [PATCH 1/3] Strip Gutenberg VideoPress block for excerpt --- .../String+StripGutenbergContentForExcerpt.swift | 10 +++++++++- .../StringStripGutenbergContentForExcerptTests.swift | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift b/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift index 61549222..ec4c89f1 100644 --- a/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift +++ b/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift @@ -8,7 +8,7 @@ extension String { /// This method is the main entry point to generate excerpts for Gutenberg content. /// public func strippingGutenbergContentForExcerpt() -> String { - return strippingGutenbergGalleries() + return strippingGutenbergGalleries().strippingGutenbergVideoPress() } /// Strips Gutenberg galleries from strings. @@ -18,4 +18,12 @@ extension String { return removingMatches(pattern: pattern, options: .caseInsensitive) } + + /// Strips Gutenberg VideoPress block. + /// + private func strippingGutenbergVideoPress() -> String { + let pattern = "(?s)\n?" + + return removingMatches(pattern: pattern, options: .caseInsensitive) + } } diff --git a/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift b/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift index ab9599e8..a53f1b47 100644 --- a/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift +++ b/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift @@ -29,4 +29,13 @@ class StringStripGutenbergContentForExcerptTests: XCTestCase { XCTAssertEqual(summary, expectedSummary) } + + func testStrippingGutenbergContentForExcerptWithVideoPress() { + let content = "

Before

\n\n
\nhttps://videopress.com/v/AbCDe?resizeToParent=true&cover=true&preloadContent=metadata&useAverageColor=true\n
\n\n

After

" + let expectedSummary = "

Before

\n

After

" + + let summary = content.strippingGutenbergContentForExcerpt() + + XCTAssertEqual(summary, expectedSummary) + } } From 39942fcbe4e3ef6156ebd7248a60f79fb5438a58 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 12 Apr 2023 12:00:01 +0200 Subject: [PATCH 2/3] Fix Trailing Whitespace violations --- ...ring+StripGutenbergContentForExcerpt.swift | 10 ++++---- ...StripGutenbergContentForExcerptTests.swift | 24 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift b/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift index ec4c89f1..71c9fe68 100644 --- a/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift +++ b/Sources/WordPressShared/Utility/String+StripGutenbergContentForExcerpt.swift @@ -4,26 +4,26 @@ import Foundation /// shown when generating post excerpts. /// extension String { - + /// This method is the main entry point to generate excerpts for Gutenberg content. /// public func strippingGutenbergContentForExcerpt() -> String { return strippingGutenbergGalleries().strippingGutenbergVideoPress() } - + /// Strips Gutenberg galleries from strings. /// private func strippingGutenbergGalleries() -> String { let pattern = "(?s)" - + return removingMatches(pattern: pattern, options: .caseInsensitive) } - + /// Strips Gutenberg VideoPress block. /// private func strippingGutenbergVideoPress() -> String { let pattern = "(?s)\n?" - + return removingMatches(pattern: pattern, options: .caseInsensitive) } } diff --git a/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift b/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift index a53f1b47..e73f269c 100644 --- a/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift +++ b/Tests/WordPressSharedTests/StringStripGutenbergContentForExcerptTests.swift @@ -2,40 +2,40 @@ import XCTest @testable import WordPressShared class StringStripGutenbergContentForExcerptTests: XCTestCase { - + func testStrippingGutenbergContentForExcerpt() { let content = "

Some Content

" let expectedSummary = "

Some Content

" - + let summary = content.strippingGutenbergContentForExcerpt() - + XCTAssertEqual(summary, expectedSummary) } - + func testStrippingGutenbergContentForExcerptWithGallery() { let content = "

Some Content

" let expectedSummary = "

Some Content

" - + let summary = content.strippingGutenbergContentForExcerpt() - + XCTAssertEqual(summary, expectedSummary) } - + func testStrippingGutenbergContentForExcerptWithGallery2() { let content = "

Before

\n

After

" let expectedSummary = "

Before

\n

After

" - + let summary = content.strippingGutenbergContentForExcerpt() - + XCTAssertEqual(summary, expectedSummary) } - + func testStrippingGutenbergContentForExcerptWithVideoPress() { let content = "

Before

\n\n
\nhttps://videopress.com/v/AbCDe?resizeToParent=true&cover=true&preloadContent=metadata&useAverageColor=true\n
\n\n

After

" let expectedSummary = "

Before

\n

After

" - + let summary = content.strippingGutenbergContentForExcerpt() - + XCTAssertEqual(summary, expectedSummary) } } From 02c7bdb1f0ab68a0b1b86e196680c99f485aba51 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 12 Apr 2023 12:00:40 +0200 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb8996e7..216d843d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ _None._ ### New Features -_None._ +- Strip Gutenberg VideoPress block for excerpt [#339] ### Bug Fixes