Resolved

Astro static site missing canonical URLs and Open Graph meta tags

Astro
SEO
Frontend
Static Site Generation
Open Graph
Meta Tags
TypeScript
Web Performance

Manual SEO implementation in Astro 5.12.8 caused missing canonical URLs, wrong language declarations and incomplete Open Graph tags | Relative image URLs broke social media previews and no per-page indexing control existed

Refactored the manual meta tag implementation in Astro to address critical SEO deficiencies using the astro-seo package. The migration improved canonical URLs, language declarations, and Open Graph tags while adding per-page indexing control.

Issue

The static site suffered from multiple SEO deficiencies:

  • Missing canonical URLs, risking duplicate content penalties.
  • Incorrect language declarations (lang="en" despite German content).
  • Incomplete Open Graph tags (missing og:url, og:locale, og:site_name).
  • Relative image URLs in Open Graph tags breaking social media previews.
  • No sitemap reference in the <head> section.
  • No per-page indexing control, causing privacy/legal pages to appear in search results.
  • Maintenance burden from inconsistent manual meta tags across 20+ lines.

Culprit

  • Manual Meta Tag Management: Meta tags were constructed without validation, leading to inconsistencies.
  • Architecture Decision: The props interface assumed relative paths were sufficient but failed for social media crawlers.
  • Language Mismatch: Hardcoded lang="en" despite the site’s German content.
  • Image URL Handling: Relative paths broke when shared on social media.

Solution

  • Package Integration: Installed astro-seo@0.8.4 for type-safe SEO implementation.
  • Layout Component Refactor: Replaced manual meta tags with a single <SEO> component in Layout.astro, auto-generating canonical URLs and absolute image paths.
  • Per-Page Indexing Control: Added noindex and nofollow props for privacy/legal pages.
  • Complete Open Graph Implementation: Ensured all required Open Graph tags were included with correct locales and site names.
  • Sitemap Reference: Added a link to the sitemap in the <head> section.
  • Verification: Confirmed proper generation of canonical URLs, Open Graph tags, and indexing controls in the build output.