{
  "id": "build-an-astro-static-seo-site",
  "type": "prompts",
  "category": "prompts",
  "locale": "en",
  "url": "/prompts/build-an-astro-static-seo-site",
  "title": "Prompt to Build an Astro Static SEO Site",
  "description": "Copy-paste prompt for scaffolding a fully optimized Astro static site with content collections, sitemap, og-images, and TypeScript.",
  "tools": [
    "Cursor",
    "Claude Code",
    "Codex",
    "Windsurf"
  ],
  "stack": [
    "Astro",
    "TypeScript",
    "Tailwind"
  ],
  "tags": [
    "astro",
    "seo",
    "typescript",
    "tailwind"
  ],
  "difficulty": "medium",
  "updated": "2026-06-08",
  "markdown": "Give this to your agent to scaffold a production-ready Astro static site with\ncontent collections, Tailwind v4, SEO meta, sitemap, and per-page OG images —\nwithout it inventing incompatible integrations or skipping canonical tags.\n\n## Main Prompt\n\n```txt title=\"Main Prompt\"\nYou are scaffolding a new Astro static site. Use Astro 5, TypeScript strict mode,\nand Tailwind CSS v4 (via @tailwindcss/vite — NOT the legacy @astrojs/tailwind integration).\n\nRequirements:\n- Initialize with `bun create astro@latest` defaults, then layer in:\n  - A `src/content/blog/` collection with a Zod schema (title, description, pubDate, tags).\n  - A shared `<BaseLayout>` with `<head>` containing: canonical URL, og:title, og:description,\n    og:image (per-page), twitter:card, and the Astro `<ViewTransitions />` component.\n  - `@astrojs/sitemap` integration configured with `customPages` for any dynamic routes.\n  - A `public/robots.txt` that disallows `/api/` and allows everything else.\n  - A `/blog/[slug].astro` dynamic route that renders MDX blog posts.\n  - A `/tags/[tag].astro` route that filters posts by tag.\n  - Tailwind applied globally via `src/styles/global.css` imported in BaseLayout.\n- All components must be `.astro` — no React unless explicitly asked.\n- Export a typed `getStaticPaths` for every dynamic route.\n- Do NOT install `@astrojs/react`, `next`, or any SSR adapter — this is a static build.\n\nStop after listing all files you plan to create or modify. Wait for my approval before writing any code.\n```\n\n## Implementation Notes\n\n- Astro 5 content collections use `defineCollection` in `src/content.config.ts`, not the old\n  `src/content/config.ts` path — confirm the agent uses the correct location.\n- Tailwind v4 ships as a Vite plugin; the old `astro.config.ts` `integrations: [tailwind()]` pattern\n  is obsolete and will cause a runtime error.\n- `getStaticPaths` must return `{ params, props }` objects; the agent sometimes returns bare strings.\n\n## Expected File Changes\n\n```txt\nastro.config.ts                          (new)\nsrc/content.config.ts                    (new)\nsrc/layouts/BaseLayout.astro             (new)\nsrc/pages/index.astro                    (new)\nsrc/pages/blog/[slug].astro              (new)\nsrc/pages/tags/[tag].astro              (new)\nsrc/styles/global.css                    (new)\npublic/robots.txt                        (new)\npackage.json                             (edited)\ntsconfig.json                            (edited)\n```\n\n## Acceptance Criteria\n\n- `bun run build` exits 0 with no type errors.\n- Each blog post page includes a unique canonical URL and `og:image` in the rendered HTML.\n- `/sitemap-index.xml` is generated and contains all blog post URLs.\n- `/robots.txt` exists and disallows `/api/`.\n\n## Test Commands\n\n```bash\nbun run build\nbun run preview\ncurl -s http://localhost:4321/sitemap-index.xml | grep '<loc>'\ncurl -s http://localhost:4321/robots.txt\nbun run typecheck\n```\n\n## Common AI Mistakes\n\n- Installing the deprecated `@astrojs/tailwind` instead of `@tailwindcss/vite`.\n- Placing `content.config.ts` at `src/content/config.ts` (old Astro 4 path).\n- Forgetting to call `getCollection('blog')` inside `getStaticPaths` — returning an empty array.\n- Adding `output: 'server'` to `astro.config.ts`, which breaks static export.\n\n## Fix Prompt\n\n```txt title=\"Fix Prompt\"\nThe build failed. Check for these issues in order:\n1. Tailwind: remove `@astrojs/tailwind` from integrations and add `@tailwindcss/vite` to the\n   `vite.plugins` array in astro.config.ts.\n2. Content config: the file must be at `src/content.config.ts` (not `src/content/config.ts`).\n3. `getStaticPaths`: each entry must be `{ params: { slug }, props: { post } }`.\nFix only the broken items. Show me the corrected diff.\n```"
}