{
  "id": "build-a-static-seo-site-with-astro",
  "type": "playbooks",
  "category": "playbooks",
  "locale": "es",
  "url": "/es/playbooks/build-a-static-seo-site-with-astro",
  "title": "Prompt-to-PR: Construye un sitio SEO estático con Astro",
  "description": "SOP completo para crear desde cero un sitio SEO estático basado en contenido con Astro, Tailwind, colecciones de contenido MDX, mapa del sitio y etiquetas canónicas.",
  "tools": [
    "Cursor",
    "Claude Code",
    "Codex",
    "Windsurf"
  ],
  "stack": [
    "Astro",
    "TypeScript",
    "Tailwind"
  ],
  "tags": [
    "astro",
    "seo",
    "tailwind",
    "typescript",
    "search"
  ],
  "difficulty": "medium",
  "updated": "2026-06-08",
  "markdown": "Crea un sitio Astro 5 completamente estático y listo para producción, optimizado para búsqueda orgánica: colecciones de contenido, tipografía de Tailwind, `@astrojs/sitemap` y metadatos `<head>` correctos desde el primer día.\n\n## 1. Requisito\n\nConstruye un sitio de marketing/contenido estático que obtenga 100 en SEO y Accesibilidad de Lighthouse. El contenido se escribe en archivos MDX administrados por las colecciones de contenido de Astro. No se necesita un framework de JavaScript: la salida es HTML+CSS puro con islas optativas.\n\n## 2. Primer Prompt\n\n```txt title=\"First Prompt\"\nScaffold a new Astro 5 static SEO site from scratch in the current directory.\n\nRequirements:\n1. Init with: `bunx create astro@latest . --template minimal --typescript strict --no-git`\n2. Add integrations:\n   - `@astrojs/tailwind` with `@tailwindcss/typography`\n   - `@astrojs/sitemap`\n   - `@astrojs/mdx`\n3. Create a content collection `blog` in `src/content/blog/` with this Zod schema:\n   title, description, pubDate (Date), updatedDate (Date, optional),\n   author (string, default \"Admin\"), tags (string[], default []), draft (bool, default false).\n4. Create a BaseLayout.astro with:\n   - A `<head>` block: charset, viewport, canonical (`Astro.url.href`),\n     og:title, og:description, og:url, og:type, twitter:card.\n   - Accept `title`, `description`, `image` props.\n5. Create pages:\n   - `/` — hero + last 6 non-draft posts\n   - `/blog` — paginated list (10 per page) using `paginate()`\n   - `/blog/[slug]` — single post rendered with `<Content />`\n   - `/tags/[tag]` — posts filtered by tag\n6. Create `src/content/blog/hello-world.mdx` as a real sample post.\n7. Configure `astro.config.ts`:\n   - `site: process.env.SITE_URL ?? \"http://localhost:4321\"`\n   - `integrations: [tailwind(), sitemap(), mdx()]`\n   - `output: \"static\"`\n8. Add a `.env.example` with `SITE_URL=https://example.com`.\n```\n\n## 3. Cambios de archivos esperados\n\n```txt\nastro.config.ts\ntailwind.config.ts\nsrc/content.config.ts                    (blog collection schema)\nsrc/layouts/BaseLayout.astro             (head + canonical + OG tags)\nsrc/pages/index.astro\nsrc/pages/blog/index.astro               (paginated)\nsrc/pages/blog/[slug].astro\nsrc/pages/tags/[tag].astro\nsrc/content/blog/hello-world.mdx\n.env.example\npackage.json                             (updated with all integrations)\n```\n\n## 4. Lista de verificación\n\n- `astro.config.ts` establece `site` — necesario para que `@astrojs/sitemap` emita URLs absolutas.\n- `BaseLayout.astro` genera un `<link rel=\"canonical\">` usando `Astro.url.href`.\n- La página de lista del blog usa `Astro.props.page.data` de `paginate()` — no una llamada directa a `getCollection()`.\n- Los borradores (`draft: true`) se excluyen en producción mediante la comprobación de `import.meta.env.PROD`.\n- Se establece `<html lang=\"en\">` en el elemento raíz.\n- `tailwind.config.ts` incluye el plugin `typography` y apunta a `src/**/*.{astro,mdx}`.\n- La integración de `sitemap()` está presente — verifica que `dist/sitemap-index.xml` exista después de ejecutar `bun run build`.\n\n## 5. Comandos de prueba\n\n```bash\nbun install\nbun run dev\n# visit http://localhost:4321 and confirm hero + posts render\n\nbun run build\n# expect zero errors\n\nbun run preview\n# check /sitemap-index.xml and /sitemap-0.xml exist\n# check /blog and /blog/hello-world render with correct <title> and canonical\n\n# Lighthouse CLI smoke test (optional)\nbunx lighthouse http://localhost:4321 --output json --quiet | jq '.categories.seo.score'\n# expect 1 (100%)\n```\n\n## 6. Fallos comunes\n\n- **El mapa del sitio genera URLs relativas** — falta `site` en `astro.config.ts`. Agrégalo.\n- **`getCollection` devuelve borradores en producción** — filtra: `posts.filter(p => !p.data.draft || !import.meta.env.PROD)`.\n- **Error 404 de paginación en `/blog`** — la primera página debe ser `/blog/` (índice), no `/blog/1`. Por defecto, `paginate()` de Astro genera `/blog/`, `/blog/2/`, etc.\n- **Contenido MDX sin estilo** — falta la clase `prose` de `@tailwindcss/typography` en el envoltorio del artículo en `[slug].astro`.\n- **Las etiquetas OG usan una ruta de imagen relativa** — debe ser una URL absoluta. Prefija con `Astro.site`.\n\n## 7. Prompt de corrección\n\n```txt title=\"Fix Prompt\"\nThe sitemap at /sitemap-0.xml contains relative paths like \"/blog/hello-world\"\ninstead of absolute URLs like \"https://example.com/blog/hello-world\".\n\nFix: add `site: \"https://example.com\"` (or `process.env.SITE_URL`) to the\ntop-level astro.config.ts object. The sitemap integration reads this value\nto prefix all URLs.\n```\n\n## 8. Descripción del PR\n\n```md title=\"PR description\"\n## Init: Static Astro 5 SEO site\n\n- Astro 5 + TypeScript strict + Tailwind (with `@tailwindcss/typography`)\n- `@astrojs/sitemap` and `@astrojs/mdx` integrations\n- Content collection `blog` with Zod schema (title, description, pubDate, tags, draft)\n- BaseLayout with canonical, OG, and Twitter Card meta tags\n- Pages: home, paginated blog list, single post, tag archive\n- Sample `hello-world.mdx` post\n- `bun run build` emits `sitemap-index.xml` and all static pages\n```"
}