--- name: building-static-sites description: Use when creating static websites with Next.js static export - covers YAML-based content, image optimization, form handling, SEO, and deployment to GitHub Pages/Netlify/Vercel --- # Building Static Sites ## Overview Static site generation with **Next.js** (`output: 'export'`) for marketing sites, documentation, portfolios, and blogs. Extends `building-with-nextjs` for static export. ## When to Use - Marketing sites, docs, blogs, portfolios, landing pages - No auth, no server-side logic, no real-time data ## Configuration **next.config.ts:** ```typescript const nextConfig = { output: 'export', // Enable static HTML export images: { unoptimized: true, // Or use optimizer plugin }, } ``` **Build output:** `out/` directory with static HTML ## YAML-Based Content (Recommended) **Structure:** ``` content/ ├── global.yaml # Site-wide content ├── features.yaml # Reusable blocks └── pages/ ├── home.yaml ├── about.yaml └── contact.yaml ``` **Type-safe loading:** ```typescript // lib/content-types.ts export interface GlobalContent { site: { title: string; description: string; url: string } navigation: { links: Array<{ href: string; label: string }> } } // lib/content.ts import fs from 'fs' import path from 'path' import yaml from 'js-yaml' export function getGlobalContent(): GlobalContent { const filePath = path.join(process.cwd(), 'content', 'global.yaml') const content = fs.readFileSync(filePath, 'utf8') return yaml.load(content) as GlobalContent } ``` **Example YAML:** ```yaml # content/global.yaml site: title: "My Company" description: "We build great things" navigation: links: - href: "/" label: "Home" - href: "/about" label: "About" ``` **Usage:** ```typescript // app/page.tsx import { getHomeContent } from '@/lib/content' export default function HomePage() { const content = getHomeContent() return

{content.hero.headline}

} ``` **Dependencies:** ```bash pnpm add js-yaml pnpm add -D @types/js-yaml ``` ## Image Optimization **Option 1: Pre-optimize manually** ```bash pnpm add -D sharp-cli sharp resize 1920 --quality 85 --format webp public/images/*.{jpg,png} ``` **Option 2: Build-time optimization** ```bash pnpm add -D next-image-export-optimizer ``` **Option 3: CDN-based (Recommended)** - Use Cloudflare Images, imgix, or similar - No build processing needed ## Form Handling See `integrating-formspree-forms` skill for complete setup. **Quick example:** ```typescript 'use client' import { useForm } from '@formspree/react' export default function ContactForm() { const [state, handleSubmit] = useForm("YOUR_FORM_ID") if (state.succeeded) { return

Thanks for your message!

} return (