fix: add fallback to strip nbsp-separated publisher names from excerpts
Google News RSS excerpts use double non-breaking spaces followed by the publisher name (e.g. "...habitat News-Medical"). When the source field is "news.google.com" rather than the actual publisher, the exact-match logic can't strip it. This adds a regex fallback that catches trailing nbsp-separated capitalized names. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user