diff --git a/includes/class-peptide-news-rest-api.php b/includes/class-peptide-news-rest-api.php index d53c7af..90c7dc9 100644 --- a/includes/class-peptide-news-rest-api.php +++ b/includes/class-peptide-news-rest-api.php @@ -236,7 +236,7 @@ class Peptide_News_Rest_API { } } - // Fallback: strip trailing " - Short Publisher Name" patterns (1-5 words). + // Fallback 1: strip trailing " - Short Publisher Name" patterns (1-5 words). // Only strips if the part after the separator looks like a publisher name // (starts with uppercase, no sentence-ending punctuation). $pattern = '/\s+[-\x{2013}\x{2014}|]\s+[A-Z][A-Za-z0-9\s.\'\-]{0,50}$/u'; @@ -245,6 +245,15 @@ class Peptide_News_Rest_API { return rtrim( $candidate ); } + // Fallback 2: strip trailing nbsp-separated publisher names. + // Google News RSS excerpts use double non-breaking space + publisher name + // when the source field doesn't match (e.g., source = "news.google.com"). + $nbsp_pattern = '/(?:\x{00A0}{1,2}|\s{2,})[A-Z][A-Za-z0-9\s.\'\-]{0,50}$/u'; + $candidate = preg_replace( $nbsp_pattern, '', $text ); + if ( $candidate !== $text && strlen( $candidate ) > strlen( $text ) * 0.4 ) { + return rtrim( $candidate ); + } + return $text; } diff --git a/peptide-news-plugin/includes/class-peptide-news-rest-api.php b/peptide-news-plugin/includes/class-peptide-news-rest-api.php index b5db289..407dbeb 100644 --- a/peptide-news-plugin/includes/class-peptide-news-rest-api.php +++ b/peptide-news-plugin/includes/class-peptide-news-rest-api.php @@ -230,7 +230,7 @@ class Peptide_News_Rest_API { } } - // Fallback: strip trailing " - Short Publisher Name" patterns (1-5 words). + // Fallback 1: strip trailing " - Short Publisher Name" patterns (1-5 words). // Only strips if the part after the separator looks like a publisher name // (starts with uppercase, no sentence-ending punctuation). $pattern = '/\s+[-–—|]\s+[A-Z][A-Za-z0-9\s.\'-]{0,50}$/u'; @@ -239,6 +239,15 @@ class Peptide_News_Rest_API { return rtrim( $candidate ); } + // Fallback 2: strip trailing nbsp-separated publisher names. + // Google News RSS excerpts use double non-breaking space + publisher name + // when the source field doesn't match (e.g., source = "news.google.com"). + $nbsp_pattern = '/(?:\x{00A0}{1,2}|\s{2,})[A-Z][A-Za-z0-9\s.\'\-]{0,50}$/u'; + $candidate = preg_replace( $nbsp_pattern, '', $text ); + if ( $candidate !== $text && strlen( $candidate ) > strlen( $text ) * 0.4 ) { + return rtrim( $candidate ); + } + return $text; }