Technical SEO - Fix og:image dimensions, hreflang dedupe + x-default, html lang#1377
Technical SEO - Fix og:image dimensions, hreflang dedupe + x-default, html lang#1377slightlyoffbeat wants to merge 1 commit into
Conversation
I'm checking http://localhost:8000/en-US/compare/chrome/ which already had a custom |
There was a problem hiding this comment.
Pull request overview
This PR batches several small, head-metadata updates to improve firefox.com technical SEO signals, social preview rendering, and accessibility language metadata for en-US pages.
Changes:
- Emit correct
<html lang="{{ LANG }}">for en-US (stop rewritingen-US→en). - Add
og:image:width/og:image:heightalongside the existingog:imagetag inbase-flare26.html. - Deduplicate
hreflang="en"for en-US and emithreflang="x-default"on all pages (not homepage-only), with a corresponding test assertion update.
Review notes (per repo custom Copilot instructions):
- Two non-blocking suggestions were left: (1) avoid repeating the
image(..., "width-1200")rendition lookup 3x in the same template render, and (2) add a test assertion for the new sitewidex-defaultoutput to reduce regression risk.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
springfield/cms/templates/cms/base-flare26.html |
Fixes html[lang] for en-US and adds Open Graph image dimensions. |
springfield/base/templates/includes/canonical-url.html |
Emits x-default sitewide and removes redundant hreflang="en" for en-US. |
springfield/cms/tests/test_locale_fallback_rendering.py |
Updates hreflang assertions for the en-US dedupe behavior. |
| <meta property="og:url" content="{% filter trim|absolute_url %}{% block page_og_url %}{{ settings.CANONICAL_URL + '/' + LANG + canonical_path }}{% endblock %}{% endfilter %}"> | ||
| <meta property="og:image" content="{% filter trim|absolute_url %}{% block page_image %}{% if page and page.og_image %}{% set img = image(page.og_image, "width-1200") %}{{ img.url }}{% else %}{{ static('img/firefox/flare/og.png') }}{% endif %}{% endblock %}{% endfilter %}"> | ||
| <meta property="og:image:width" content="{% block page_image_width %}{% if page and page.og_image %}{% set img = image(page.og_image, "width-1200") %}{{ img.width }}{% else %}1200{% endif %}{% endblock %}"> | ||
| <meta property="og:image:height" content="{% block page_image_height %}{% if page and page.og_image %}{% set img = image(page.og_image, "width-1200") %}{{ img.height }}{% else %}630{% endif %}{% endblock %}"> |
| assert f'rel="canonical" href="{settings.CANONICAL_URL}/en-US{page_path}"' in html | ||
| assert '<meta name="robots" content="noindex,follow">' not in html | ||
| # en-US should emit both hreflang="en" and hreflang="en-US". | ||
| assert f'hreflang="en" href="{settings.CANONICAL_URL}/en-US{page_path}"' in html | ||
| # en-US should emit hreflang="en-US" only (duplicate bare hreflang="en" was removed for SEO clarity). | ||
| assert f'hreflang="en" href="{settings.CANONICAL_URL}/en-US{page_path}"' not in html | ||
| assert f'hreflang="en-US" href="{settings.CANONICAL_URL}/en-US{page_path}"' in html |
|
I ticked off most of the manual test plan. Also, just pushed the branch to |
|
Removing myself as reviewer as I don't have the expertise to add anything to the current reviews. |
Summary
Four small head-metadata fixes batched into one PR (A6 b–d in the firefox.com technical SEO master plan):
og:image:widthandog:image:heightadded — improves how shared firefox.com links render in social previews (LinkedIn, Slack, X, iMessage, Discord, etc.) by declaring image dimensions upfront.hreflang="en"removed — en-US pages were declaring bothhreflang="en"andhreflang="en-US"; the bareenoverlaps withen-USand creates a redundant signal to Google. Dropped the duplicate.x-defaultextended to all pages — was previously homepage-only; now emitted on every page so users in unsupported locales reach the right fallback regardless of which URL they hit directly.<html lang>attribute corrected for en-US — was emittinglang="en"due to a|replace('en-US', 'en')filter; now emitslang="en-US"to match the actual locale and improve screen-reader pronunciation.All four are zero-visual-change improvements to SEO, social-sharing, and accessibility signals. No change to user-visible firefox.com behavior. No CSS, JS, or layout impact.
Why
What changed
springfield/cms/templates/cms/base-flare26.htmllang="{{ LANG|replace('en-US', 'en') }}"→lang="{{ LANG }}"{% block %}slots emitting dimensions adjacent to the existingog:imagetag:{% block page_image_width %}defaults to{{ img.width }}for CMS pages with a customog_image, otherwise1200{% block page_image_height %}defaults to{{ img.height }}for CMS pages with a customog_image, otherwise630og.pngis confirmed 1200×630, matching the hardcoded fallback valuesspringfield/base/templates/includes/canonical-url.html{% if is_homepage %}...{% endif %}wrapper around thex-defaultemission so it fires on every page<link rel="alternate" hreflang="en" ...>line in the en-US locale block; onlyhreflang="en-US"remainsspringfield/cms/tests/test_locale_fallback_rendering.pyhreflang="en"ANDhreflang="en-US"; now assertshreflang="en"is not present andhreflang="en-US"IS present. Comment updated.Scope notes
base-flare.html,base-protocol.html) intentionally not updated — they're being sunset and still use the|replace('en-US', 'en')filter. Pages extending those bases continue to emitlang="en"on en-US locales for now. Known transitional state.{% block page_image %}with non-1200×630 images (firefox/features/fast.html,firefox/browsers/compare/chrome.html, various landing pages, etc.). They'll get the hardcoded 1200×630 default for width/height. Social platforms fall back to fetching the image and reading real dimensions when declared values don't match — wrong values don't break previews, just less optimal. Templates can opt into accurate dimensions by overriding the newpage_image_width/page_image_heightblocks when next touched. Accepted trade-off.Fallback behavior preserved
Removing
hreflang="en"does not remove fallback. The two mechanisms are:hreflang="en-US"as the closest English variant.x-defaultpoints to the unprefixed canonical URL, which hits the locale-negotiation middleware and routes them to the closest supported locale via Accept-Language. This used to be homepage-only; now sitewide. Fallback strengthened, not removed.Audit / review
Performed a thorough code audit for unintended side effects. Findings:
:lang()selectors anywhere in the codebase (confirmed via grep)document.documentElement.langfor value (media/js/firefox/features/translate.es6.js) — uses it withIntl.DisplayNames, which handles both"en"and"en-US"identically for English display. No behavior change.<html>(sentry-consent, stub-attribution, gtm-snippet, etc.) reads data-attributes or manipulates classList, notlang. No impact.langhidden input (newsletter_form.html:53-54) and corresponding test (test_pages.py:320) operate on the PythonLANGtemplate variable, not on the HTML attribute. Unchanged behavior —LANG.startswith('en-')still evaluates correctly.403_csrf.html,cron-health-check.html) have hardcoded<html lang="en">and don't useLANG— unaffected.<html lang>value.Test results
Ran the full affected test suites locally:
springfield/cms/tests/test_locale_fallback_rendering.py— 21/21 pass (includes the updated assertion)springfield/cms/tests/— 652/656 pass (4 failures pre-existing inBootstrapLocalAdminTests, unrelated to A6 —bootstrap_local_admincommand leaking from local.env)springfield/firefox/tests/— 531/531 passZero regressions introduced by A6.
Manual test plan
pytest springfield/cms/tests/test_locale_fallback_rendering.py -v→ passes<html lang="en-US">,og:image:width="1200",og:image:height="630", singlehreflang="en-US"entry (nohreflang="en"),x-defaultpresentx-defaultpresent (was previously homepage-only)og_image→og:image:widthandog:image:heightreflect the actual rendition dimensionspage_image(e.g./firefox/features/fast/) → emits default 1200×630 (accepted trade-off)/fr/,/pt-BR/) →<html lang="fr">,<html lang="pt-BR">unchanged