fix: prefer first-post F95 covers and banners over metadata thumbnails
This commit is contained in:
1 parent
e48521bdfb
commit
5b911d1e3b
3 files changed
+49
-8
No files matched your search
@@ -29,11 +29,41 @@ def page(meta="", post="", reply=""):
|
||||
|
||||
|
||||
def test_og_preview_and_existing_metadata():
|
||||
result = f95.parse(page(f'<meta property="og:image" content="{IMAGE}">',
|
||||
'<img class="bbImage" src="/attachments/other.jpg">'))
|
||||
result = f95.parse(page(f'<meta property="og:image" content="{IMAGE}">'))
|
||||
assert result == {"title": "Example", "description": "A story", "tags": [], "image_url": IMAGE, "logged_in": None}
|
||||
|
||||
|
||||
def test_mist_banner_beats_metadata_thumbnail_and_earlier_inline_image():
|
||||
banner = ("https://attachments.f95zone.to/2022/03/1736427_F95Banner_Sideversion.png"
|
||||
"?h=test-signature&e=1793113200&u=42")
|
||||
escaped = banner.replace("&", "&")
|
||||
html = page('<meta property="og:image" content="/attachments/thumbnail.jpg">',
|
||||
'<img class="bbImage" src="/attachments/screenshot.jpg">'
|
||||
f'<img src="{escaped}" data-src="{escaped}" data-url="" '
|
||||
'class="bbImage lazyloaded" data-zoom-target="1" alt="F95 Cover.png" '
|
||||
'title="F95 Cover.png" width="1200" height="500" loading="lazy">',
|
||||
'<img class="bbImage" src="/attachments/reply-cover.png">')
|
||||
assert f95.parse(html)["image_url"] == banner
|
||||
|
||||
|
||||
@pytest.mark.parametrize("attributes", [
|
||||
'alt="F95 Cover.png"', 'title="Game Cover"',
|
||||
'data-src="/attachments/123_F95Banner_Sideversion.png"',
|
||||
])
|
||||
def test_cover_identified_by_alt_title_or_filename(attributes):
|
||||
html = page(post='<img class="bbImage" src="/first.jpg">'
|
||||
f'<img class="bbImage" src="/chosen.jpg" {attributes}>')
|
||||
expected = "/attachments/123_F95Banner_Sideversion.png" if "data-src" in attributes else "/chosen.jpg"
|
||||
assert f95.parse(html)["image_url"] == "https://f95zone.to" + expected
|
||||
|
||||
|
||||
def test_first_post_image_preferred_over_og_thumbnail_without_cover_marker():
|
||||
html = page('<meta property="og:image" content="/thumbnail.jpg">',
|
||||
'<div class="bbCodeSpoiler"><img class="bbImage" src="/hidden-cover.png"></div>'
|
||||
'<img class="bbImage" src="/first.jpg"><img class="bbImage" src="/second.jpg">')
|
||||
assert f95.parse(html)["image_url"] == "https://f95zone.to/first.jpg"
|
||||
|
||||
|
||||
def test_first_post_lazy_image_fallback_ignores_logo_spoilers_and_replies():
|
||||
html = page('<meta property="og:image" content="/styles/logo.png">',
|
||||
'<img class="avatar" src="/avatar.jpg">'
|
||||
|
||||
Reference in new issue
Block a user