Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions scripts/rebrand/compare_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,15 @@ def _equivalent_descriptions(before, after):
def _without_default_images(before, after):
"""Drop the default share images and their alt texts where main's default became a tray, and nothing else."""
def drop(tags, pattern, alt):
keys = ("og:image", "twitter:image")
images = {tag for tag in tags for key in keys if tag.startswith(key + "=") and pattern.fullmatch(tag[len(key) + 1:])}
alts = {f"{key}:alt={alt}" for key in keys}
if len(images) != len(keys) or not alts <= set(tags):
return None
return [tag for tag in tags if tag not in images | alts]
dropped = []
for key in ("og:image", "twitter:image"):
images = [tag for tag in tags if tag.startswith(key + "=")]
alts = [tag for tag in tags if tag.startswith(key + ":alt=")]
# Duplicate tags are left for the ordinary comparison.
if len(images) != 1 or not pattern.fullmatch(images[0][len(key) + 1:]) or alts != [f"{key}:alt={alt}"]:
return None
dropped += images + alts
return [tag for tag in tags if tag not in dropped]

old, new = drop(before, _OLD_DEFAULT_IMAGE, _OLD_DEFAULT_ALT), drop(after, _TRAY_IMAGE, _TRAY_ALT)
return (before, after) if old is None or new is None else (old, new)
Expand Down
3 changes: 3 additions & 0 deletions scripts/tests/test_rebrand_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ def test_the_default_share_image_may_become_a_brick_tray(self):
(tray.replace("_hu_0123456789abcdef", ""), new_alt)):
with self.subTest(image=image, alt=alt):
self.assertIn("a", compare_heads({"a": before}, {"a": self.default_tags(image, alt)}))
for extra in ("og:image=" + tray, "twitter:image=https://forrt.org/other.png", "og:image:alt=" + new_alt):
with self.subTest(extra=extra):
self.assertIn("a", compare_heads({"a": before}, {"a": sorted(after + [extra])}))
# A page that had an image of its own must keep it, and nothing else may change along with the default.
own = self.default_tags("https://forrt.org/rebrand-doors/img/own.png", old_alt)
self.assertIn("a", compare_heads({"a": own}, {"a": after}))
Expand Down
Loading