diff --git a/goodnews/enrich.py b/goodnews/enrich.py index 966e7ac..1f2fa4e 100644 --- a/goodnews/enrich.py +++ b/goodnews/enrich.py @@ -34,11 +34,12 @@ MAX_REDIRECTS = 3 _META_RE = re.compile(rb"]*>", re.IGNORECASE) _HEAD_END_RE = re.compile(rb"", re.IGNORECASE) -# Substrings that mark a branded/generic share image rather than the article's -# own picture (e.g. BBC burns "BBC NEWS" into branded_news; NPR uses a default). -# We'd rather show no image (typographic hero) than a competitor logo. +# Substrings that mark a generic placeholder/default share image rather than the +# article's own picture (e.g. NPR's facebook-default). We'd rather show no image +# (typographic hero) than a generic logo card. NOTE: do NOT add "branded_news" — +# that's BBC's normal CDN path for real article photos, so rejecting it threw away +# every BBC hero image and fell back to the tiny RSS thumbnail. _GENERIC_IMAGE_MARKERS = ( - "branded_news", "facebook-default", "default-wide", "default-fb", diff --git a/tests/test_enrich.py b/tests/test_enrich.py index 8510caf..7afde6d 100644 --- a/tests/test_enrich.py +++ b/tests/test_enrich.py @@ -71,12 +71,15 @@ def test_enrich_upgrades_existing_feed_image(tmp_path): c.close() -def test_rejects_branded_and_generic_share_images(): - assert og_image_from_html(b'') is None +def test_rejects_generic_share_images(): + # genuine placeholder/default share images are skipped assert og_image_from_html(b'') is None - # a real article image still comes through + assert og_image_from_html(b'') is None + # a real article image comes through assert og_image_from_html(b'') == "https://x.com/real-photo.jpg" - # if the first og is branded but a later one is real, take the real one - html = (b'' + # BBC's branded_news path is a REAL photo path, not a placeholder — keep it + assert og_image_from_html(b'') == "https://ichef.bbci.co.uk/news/1024/branded_news/x.jpg" + # if the first og is a generic placeholder but a later one is real, take the real one + html = (b'' b'') assert og_image_from_html(html) == "https://x.com/article.jpg"