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.4for type-safe SEO implementation. - Layout Component Refactor: Replaced manual meta tags with a single
<SEO>component inLayout.astro, auto-generating canonical URLs and absolute image paths. - Per-Page Indexing Control: Added
noindexandnofollowprops 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.