fix: strip source names from excerpts using nbsp separators

Google News RSS excerpts use    (double non-breaking spaces)
to separate the excerpt text from the source name. Added html_entity_decode
and nbsp-based separators to handle this pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Terence Ong
2026-04-08 10:38:06 +07:00
parent c13919c217
commit 8fe3d828cd
2 changed files with 24 additions and 2 deletions

View File

@@ -192,7 +192,18 @@ class Peptide_News_Rest_API {
return $text;
}
$separators = array( ' - ', ' | ', ' — ', ' – ', ' // ' );
// Decode HTML entities first so &nbsp; becomes actual characters.
$text = html_entity_decode( $text, ENT_QUOTES | ENT_HTML5, 'UTF-8' );
// Common separators between title/excerpt and source name.
// Includes regular spaces, non-breaking spaces (\xC2\xA0), and typographic dashes.
$nbsp = "\xC2\xA0"; // UTF-8 non-breaking space
$separators = array(
' - ', ' | ', ' — ', ' – ', ' // ',
$nbsp . $nbsp, // double non-breaking space (Google News RSS excerpts)
' ', // double regular space
$nbsp, // single non-breaking space
);
// Build list of source names to try matching against.
$source_names = array();

View File

@@ -183,7 +183,18 @@ class Peptide_News_Rest_API {
return $text;
}
$separators = array( ' - ', ' | ', ' — ', ' – ', ' // ' );
// Decode HTML entities first so &nbsp; becomes actual characters.
$text = html_entity_decode( $text, ENT_QUOTES | ENT_HTML5, 'UTF-8' );
// Common separators between title/excerpt and source name.
// Includes regular spaces, non-breaking spaces (\xC2\xA0), and typographic dashes.
$nbsp = "\xC2\xA0"; // UTF-8 non-breaking space
$separators = array(
' - ', ' | ', ' — ', ' – ', ' // ',
$nbsp . $nbsp, // double non-breaking space (Google News RSS excerpts)
' ', // double regular space
$nbsp, // single non-breaking space
);
// Build list of source names to try matching against.
$source_names = array();