Skip to content

fix: only emit hreflang alternates for existing translations#284

Merged
Mlaz-code merged 1 commit into
mainfrom
seo/hreflang-untranslated
Jul 10, 2026
Merged

fix: only emit hreflang alternates for existing translations#284
Mlaz-code merged 1 commit into
mainfrom
seo/hreflang-untranslated

Conversation

@Mlaz-code

Copy link
Copy Markdown
Collaborator

Problem

Semrush Site Audit (sharpapi.io campaign) flagged 3 new 4xx pages plus incorrect hreflang, dropping International SEO to 88% (-9) and Site Health to 95% (-4). Root cause: EN-only docs pages emit hreflang alternates for all 4 locales (es/pt-BR/de) that do not exist and 404.

Confirmed:

  • docs.sharpapi.io/{de,es,pt-BR}/api-reference/common-4xx-errors/ returns 404
  • docs.sharpapi.io/api-reference/common-4xx-errors/ (en) returns 200
  • Both the live sitemap and the EN page head list es/pt-BR/de hreflang for this EN-only page.

Fix

Only emit hreflang alternates for locales that actually have the page translated (content file present):

  • scripts/generate-sitemap.mjs: the url loop already skipped missing translations, but the hreflang alternates block mapped over all locales unconditionally. Added an existsSync filter.
  • app/[lang]/[[...mdxPath]]/page.tsx: same existence filter on the generateMetadata languages map.

Verified

  • Regenerated the sitemap: common-4xx-errors now lists only en plus x-default; a fully-translated page (api-reference/overview) still keeps all 4 locales plus x-default.
  • tsc --noEmit: clean. generate-sitemap.mjs runs as part of the build, so the deployed sitemap regenerates automatically.

🤖 Generated with Claude Code

EN-only pages (e.g. api-reference/common-4xx-errors) emitted hreflang
alternates for es/pt-BR/de in both the sitemap and the page head, pointing at
localized URLs that 404. Semrush flagged 3 4xx pages plus incorrect hreflang,
dropping International SEO.

- scripts/generate-sitemap.mjs: filter alternates to locales whose content
  file exists (the url loop already skipped missing translations; the hreflang
  block did not).
- app/[lang]/[[...mdxPath]]/page.tsx: same existence filter on the
  generateMetadata languages map.

Fully-translated pages keep all 4 locales; EN-only pages list only en and
x-default.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Mlaz-code Mlaz-code merged commit 96bcbc7 into main Jul 10, 2026
@Mlaz-code Mlaz-code deleted the seo/hreflang-untranslated branch July 10, 2026 13:49
@Mlaz-code

Copy link
Copy Markdown
Collaborator Author

Merge gate (auto-classified): gate=smoke-passed — auto-classified by the gate-log enforcer (11min after merge, no Merge gate: audit comment found). Reviewer agent: please correct if wrong by replying with Merge gate: gate=<correct-word> — <evidence>. The audit log keys on the first such token; your correction overrides this auto-classified guess.

Posted by scripts/gate-log-enforcer.py because instruction-level rules about the gate= template aren't binding (0/N adoption); structural enforcement fills the log either way.

Mlaz-code added a commit that referenced this pull request Jul 12, 2026
…285) (#286)

The api-reference/common-4xx-errors page (added Jul 8) existed only in EN,
leaving the three locale URLs 404 and each locale one page short of parity
(57 vs 58). #284 already stopped the hreflang/switcher/sitemap from pointing
at the missing URLs; this adds the translations themselves plus the sidebar
_meta entries. JSON error bodies stay verbatim EN (they document literal API
responses). Full build green: 232 pages / 4 languages indexed.

Co-authored-by: sharp-resolver[bot] <3736210+sharp-resolver[bot]@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant