# Prompt-to-PR: Construa um Site SEO Estático com Astro

> SOP completo para scaffolding de um site SEO estático orientado a conteúdo com Astro, Tailwind, MDX content collections, sitemap e tags canônicas do zero.

**Type:** Playbook  
**Tools:** Cursor, Claude Code, Codex, Windsurf  
**Stack:** Astro, TypeScript, Tailwind  
**Difficulty:** medium  
**Updated:** 2026-06-08

---

Prepare o scaffolding de um site Astro 5 totalmente estático e pronto para produção, otimizado para busca orgânica: content collections, tipografia Tailwind, `@astrojs/sitemap` e metadados corretos do `<head>` configurados desde o primeiro dia.

## 1. Requisito

Construa um site estático de marketing/conteúdo que atinja 100 no Lighthouse em SEO e Acessibilidade. O conteúdo é escrito em arquivos MDX gerenciados por content collections do Astro. Nenhum framework JavaScript é necessário — a saída é HTML+CSS puro com ilhas opcionais.

## 2. Primeiro Prompt

```txt title="First Prompt"
Scaffold a new Astro 5 static SEO site from scratch in the current directory.

Requirements:
1. Init with: `bunx create astro@latest . --template minimal --typescript strict --no-git`
2. Add integrations:
   - `@astrojs/tailwind` with `@tailwindcss/typography`
   - `@astrojs/sitemap`
   - `@astrojs/mdx`
3. Create a content collection `blog` in `src/content/blog/` with this Zod schema:
   title, description, pubDate (Date), updatedDate (Date, optional),
   author (string, default "Admin"), tags (string[], default []), draft (bool, default false).
4. Create a BaseLayout.astro with:
   - A `<head>` block: charset, viewport, canonical (`Astro.url.href`),
     og:title, og:description, og:url, og:type, twitter:card.
   - Accept `title`, `description`, `image` props.
5. Create pages:
   - `/` — hero + last 6 non-draft posts
   - `/blog` — paginated list (10 per page) using `paginate()`
   - `/blog/[slug]` — single post rendered with `<Content />`
   - `/tags/[tag]` — posts filtered by tag
6. Create `src/content/blog/hello-world.mdx` as a real sample post.
7. Configure `astro.config.ts`:
   - `site: process.env.SITE_URL ?? "http://localhost:4321"`
   - `integrations: [tailwind(), sitemap(), mdx()]`
   - `output: "static"`
8. Add a `.env.example` with `SITE_URL=https://example.com`.
```

## 3. Mudanças Esperadas nos Arquivos

```txt
astro.config.ts
tailwind.config.ts
src/content.config.ts                    (blog collection schema)
src/layouts/BaseLayout.astro             (head + canonical + OG tags)
src/pages/index.astro
src/pages/blog/index.astro               (paginated)
src/pages/blog/[slug].astro
src/pages/tags/[tag].astro
src/content/blog/hello-world.mdx
.env.example
package.json                             (updated with all integrations)
```

## 4. Lista de Verificação

- `astro.config.ts` define `site` — necessário para que `@astrojs/sitemap` emita URLs absolutas.
- `BaseLayout.astro` gera um `<link rel="canonical">` usando `Astro.url.href`.
- A página de lista do blog usa `Astro.props.page.data` de `paginate()` — não uma chamada direta a `getCollection()`.
- Posts em rascunho (`draft: true`) são excluídos em produção via guarda `import.meta.env.PROD`.
- `<html lang="en">` está definido no elemento raiz.
- `tailwind.config.ts` inclui o plugin `typography` e tem como alvo `src/**/*.{astro,mdx}`.
- A integração `sitemap()` está presente — verifique se `dist/sitemap-index.xml` existe após `bun run build`.

## 5. Comandos de Teste

```bash
bun install
bun run dev
# visit http://localhost:4321 and confirm hero + posts render

bun run build
# expect zero errors

bun run preview
# check /sitemap-index.xml and /sitemap-0.xml exist
# check /blog and /blog/hello-world render with correct <title> and canonical

# Lighthouse CLI smoke test (optional)
bunx lighthouse http://localhost:4321 --output json --quiet | jq '.categories.seo.score'
# expect 1 (100%)
```

## 6. Falhas Comuns

- **Sitemap gera URLs relativas** — `site` ausente em `astro.config.ts`. Adicione-o.
- **`getCollection` retorna rascunhos em produção** — filtre: `posts.filter(p => !p.data.draft || !import.meta.env.PROD)`.
- **Paginação 404 em `/blog`** — a primeira página deve ser `/blog/` (índice), não `/blog/1`. O `paginate()` do Astro gera `/blog/`, `/blog/2/`, etc. por padrão.
- **Conteúdo MDX sem estilo** — a classe `prose` do `@tailwindcss/typography` está faltando no wrapper do artigo em `[slug].astro`.
- **Tags OG usam caminho de imagem relativo** — devem ser URL absoluta. Prefixe com `Astro.site`.

## 7. Prompt de Correção

```txt title="Fix Prompt"
The sitemap at /sitemap-0.xml contains relative paths like "/blog/hello-world"
instead of absolute URLs like "https://example.com/blog/hello-world".

Fix: add `site: "https://example.com"` (or `process.env.SITE_URL`) to the
top-level astro.config.ts object. The sitemap integration reads this value
to prefix all URLs.
```

## 8. Descrição do PR

```md title="PR description"
## Init: Static Astro 5 SEO site

- Astro 5 + TypeScript strict + Tailwind (with `@tailwindcss/typography`)
- `@astrojs/sitemap` and `@astrojs/mdx` integrations
- Content collection `blog` with Zod schema (title, description, pubDate, tags, draft)
- BaseLayout with canonical, OG, and Twitter Card meta tags
- Pages: home, paginated blog list, single post, tag archive
- Sample `hello-world.mdx` post
- `bun run build` emits `sitemap-index.xml` and all static pages
```