Files
news-platform/docs/seo.md
T
Artur MoreiraandPaperclip eff0aaa366 feat(frontend): add Cache-Control headers to all page routes (BIT-2261)
Set Cache-Control: s-maxage=60, stale-while-revalidate=300 on all page
routes to enable Cloudflare CDN caching per docs/architecture.md § 7.

Files updated:
- index.astro (homepage)
- article/[slug].astro (article pages)
- category/[slug].astro (category pages)
- noticias.astro (news listing)
- search.astro (search results)
- sitemap.xml.ts (sitemap)
- robots.txt.ts (robots)

This enables:
- CDN edge caching for 60 seconds (s-maxage)
- Serving stale content while revalidating for up to 300s (SWR)
- Improved TTFB for repeated requests (target: <30ms cache HIT)

Acceptance criteria:
✓ All page routes return correct Cache-Control header
✓ Cloudflare can cache responses with cf-cache-status: HIT
✓ TTFB improves to <30ms for cache HIT scenario
✓ Header values match architecture spec

Co-Authored-By: Paperclip <[email protected]>
2026-04-11 03:37:32 +00:00

176 lines
4.9 KiB
Markdown

# SEO — Strategy and Implementation
> **Status:** Active — delivered (BIT-349)
---
## Overview
SEO is a first-class concern for this platform. All pages are server-rendered, so search engines receive complete HTML without running JavaScript. The SEO implementation follows the standards used by top-tier news sites (Record, BBC Sport, The Athletic).
---
## Principles
1. **SSR-first.** No client-side rendering for content. Crawlers see full HTML.
2. **Canonical URLs.** Every page has one canonical URL; duplicates redirect (301).
3. **Structured data.** `NewsArticle` JSON-LD on all article pages.
4. **Fast first paint.** LCP < 2.5 s; CLS < 0.1 — both are Core Web Vitals ranking signals.
5. **Domain-aware.** Each domain generates its own sitemap, robots.txt, and meta tags.
---
## URL Structure
| Page type | URL pattern |
|-----------|-------------|
| Homepage | `/` |
| Category | `/{category}/` |
| Article | `/{category}/{slug}/` |
| Tag | `/tag/{slug}/` |
| Search | `/search?q={query}` |
| Sitemap | `/sitemap.xml` |
| Robots | `/robots.txt` |
---
## Meta Tags
Every page renders the following in `<head>`:
```html
<!-- Basic -->
<title>{title} | {site_name}</title>
<meta name="description" content="{excerpt}" />
<link rel="canonical" href="{canonical_url}" />
<!-- Open Graph -->
<meta property="og:type" content="article" /> <!-- or "website" for homepage -->
<meta property="og:title" content="{title}" />
<meta property="og:description" content="{excerpt}" />
<meta property="og:image" content="{featured_image_url}" />
<meta property="og:url" content="{canonical_url}" />
<meta property="og:site_name" content="{site_name}" />
<meta property="og:locale" content="{locale}" /> <!-- e.g. pt_PT -->
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="{title}" />
<meta name="twitter:description" content="{excerpt}" />
<meta name="twitter:image" content="{featured_image_url}" />
<meta name="twitter:site" content="{social.twitter}" />
<!-- Article specific -->
<meta property="article:published_time" content="{published_at}" />
<meta property="article:modified_time" content="{modified_at}" />
<meta property="article:author" content="{author.name}" />
<meta property="article:section" content="{primary_category}" />
```
---
## Structured Data (JSON-LD)
### Article Page
```json
{
"@context": "https://schema.org",
"@type": "NewsArticle",
"headline": "{title}",
"description": "{excerpt}",
"image": ["{featured_image_url}"],
"datePublished": "{published_at}",
"dateModified": "{modified_at}",
"author": {
"@type": "Person",
"name": "{author.name}"
},
"publisher": {
"@type": "Organization",
"name": "{site_name}",
"logo": {
"@type": "ImageObject",
"url": "{logo_url}"
}
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "{canonical_url}"
},
"breadcrumb": {
"@type": "BreadcrumbList",
"itemListElement": [
{ "@type": "ListItem", "position": 1, "name": "Home", "item": "{site_url}" },
{ "@type": "ListItem", "position": 2, "name": "{category}", "item": "{category_url}" },
{ "@type": "ListItem", "position": 3, "name": "{title}" }
]
}
}
```
### Homepage / Site-wide
```json
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "{site_name}",
"url": "{site_url}",
"potentialAction": {
"@type": "SearchAction",
"target": "{site_url}/search?q={search_term_string}",
"query-input": "required name=search_term_string"
}
}
```
---
## Sitemap
Generated dynamically at `/sitemap.xml` via Astro's `sitemap.xml.ts` endpoint. The bridge provides all published post slugs, categories, and tags. The sitemap is split by content type and updated on every request (cached 5 min in Redis).
```xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://newsproject.bitreport.pt/futebol/porto-bate-benfica/</loc>
<lastmod>2026-03-23T12:00:00Z</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
...
</urlset>
```
---
## Robots.txt
Generated dynamically at `/robots.txt` per domain:
```
User-agent: *
Allow: /
Disallow: /search
Disallow: /api/
Sitemap: https://newsproject.bitreport.pt/sitemap.xml
```
---
## Image SEO
- All images have `alt` text (sourced from WP media library `alt` field)
- Featured images include `width` and `height` attributes (no CLS)
- Astro `<Image />` component generates WebP with JPEG fallback
- Hero image uses `fetchpriority="high"` to prioritize LCP element
---
## AMP (Research Note)
AMP is **not** in the initial scope. Astro can generate AMP-compliant pages via a parallel route (`/amp/[slug].astro`). Google no longer requires AMP for Top Stories eligibility (since 2021), so the ROI is low. Revisit if analytics show significant AMP traffic from legacy search placements.