SEO Optimization
Implement Next.js SEO with metadata, structured data, sitemaps, Open Graph tags, and technical SEO. Apply when optimizing pages for search engines, adding social sharing, or improving discoverability.
git clone --depth 1 https://github.com/ThamJiaHe/claude-code-handbook /tmp/seo-optimization && cp -r /tmp/seo-optimization/skills/examples/seo-optimization- ~/.claude/skills/seo-optimizationseo-optimization-skill.md
# SEO Optimization
Systematic SEO implementation for Next.js applications ensuring maximum search visibility and social sharing.
## Overview
This Skill enforces:
- Optimized metadata (titles, descriptions)
- Open Graph and Twitter Card tags
- JSON-LD structured data
- Sitemaps and robots.txt
- Canonical tags for duplicate prevention
- Image optimization
- Core Web Vitals optimization
- URL structure best practices
Apply when optimizing pages for search engines, adding social sharing, or improving discoverability.
## Metadata Optimization
### Static Metadata
```tsx
// app/page.tsx
export const metadata: Metadata = {
title: 'Home | My App',
description: 'Build amazing apps with modern technology',
keywords: ['Next.js', 'React', 'TypeScript'],
authors: [{ name: 'Your Name' }],
viewport: 'width=device-width, initial-scale=1',
robots: 'index, follow'
};
export default function HomePage() {
return <div>Home</div>;
}
```
### Dynamic Metadata (generateMetadata)
```tsx
// app/blog/[slug]/page.tsx
import { Metadata } from 'next';
export async function generateMetadata(
{ params }: { params: { slug: string } }
): Promise<Metadata> {
const post = await getPost(params.slug);
return {
title: post.title,
description: post.excerpt,
keywords: post.tags,
openGraph: {
title: post.title,
description: post.excerpt,
url: `https://example.com/blog/${post.slug}`,
siteName: 'My Blog',
images: [
{
url: post.image,
width: 1200,
height: 630,
alt: post.title
}
],
type: 'article',
publishedTime: post.publishedAt,
authors: [post.author]
}
};
}
export default async function BlogPost(
{ params }: { params: { slug: string } }
) {
const post = await getPost(params.slug);
return (
<article>
<h1>{post.title}</h1>
<p>{post.content}</p>
</article>
);
}
```
## Open Graph & Social Sharing
### Complete Open Graph Setup
```tsx
// app/layout.tsx
export const metadata: Metadata = {
metadataBase: new URL('https://example.com'),
title: 'My App',
description: 'The best app ever',
openGraph: {
type: 'website',
locale: 'en_US',
url: 'https://example.com',
siteName: 'My App',
title: 'My App',
description: 'The best app ever',
images: [
{
url: '/og-image.png',
width: 1200,
height: 630,
alt: 'My App'
}
]
},
twitter: {
card: 'summary_large_image',
title: 'My App',
description: 'The best app ever',
images: ['/og-image.png'],
creator: '@yourhandle'
}
};
```
### Article Metadata (Blog Post)
```tsx
const metadata: Metadata = {
openGraph: {
type: 'article',
publishedTime: '2025-01-15T10:00:00Z',
modifiedTime: '2025-01-20T15:30:00Z',
authors: ['John Doe'],
tags: ['Next.js', 'SEO', 'Performance']
}
};
```
## JSON-LD Structured Data
### Product Schema
```tsx
// app/products/[id]/page.tsx
export default function ProductPage({ params }) {
const product = getProduct(params.id);
const structuredData = {
'@context': 'https://schema.org',
'@type': 'Product',
name: product.name,
description: product.description,
image: product.image,
brand: {
'@type': 'Brand',
name: 'My Store'
},
offers: {
'@type': 'Offer',
price: product.price,
priceCurrency: 'USD',
availability: 'https://schema.org/InStock'
},
aggregateRating: {
'@type': 'AggregateRating',
ratingValue: product.rating,
reviewCount: product.reviews.length
}
};
return (
<>
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData) }}
/>
<div>
<h1>{product.name}</h1>
<p>{product.description}</p>
<p>Price: ${product.price}</p>
</div>
</>
);
}
```
### Organization Schema
```tsx
// app/layout.tsx
export default function RootLayout({ children }) {
const organizationSchema = {
'@context': 'https://schema.org',
'@type': 'Organization',
name: 'My Company',
url: 'https://example.com',
logo: 'https://example.com/logo.png',
description: 'Company description',
sameAs: [
'https://twitter.com/mycompany',
'https://linkedin.com/company/mycompany',
'https://facebook.com/mycompany'
],
contact: {
'@type': 'ContactPoint',
contactType: 'Customer Support',
email: 'support@example.com'
}
};
return (
<html>
<head>
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(organizationSchema) }}
/>
</head>
<body>{children}</body>
</html>
);
}
```
## Sitemaps
### Static Sitemap
```ts
// app/sitemap.ts
import { MetadataRoute } from 'next';
export default function sitemap(): MetadataRoute.Sitemap {
return [
{
url: 'https://example.com',
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1
},
{
url: 'https://example.com/about',
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 0.8
},
{
url: 'https://example.com/contact',
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 0.8
}
];
}
```
### Dynamic Sitemap (Blog Posts)
```ts
// app/sitemap.ts
import { MetadataRoute } from 'next';
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const posts = await getAllPosts();
const postUrls = posts.map(post => ({
url: `https://example.com/blog/${post.slug}`,
lastModified: post.updatedAt || post.publishedAt,
changeFrequency: 'weekly' as const,
priority: 0.7
}));
const staticRoutes: MetadataRoute.Sitemap = [
{
url: 'https://example.com',
lastModified: new Date(),
changeFrequency: 'yearly' as const,
priority:Build REST APIs with proper error handling, status codes, request validation, response formatting, and rate limiting. Apply when creating API routes, handling errors, validating input, or designing API responses.
Harden REST and GraphQL APIs against common attack vectors. Apply when building API endpoints, implementing authentication, handling file uploads, or exposing APIs to external consumers.
Deploy Node.js applications on AWS using EC2, RDS, and managed services with security best practices. Apply when setting up AWS infrastructure, configuring databases, managing security, or optimizing costs.
Rapidly fix build failures, type errors, and lint issues with minimal diffs. Apply when builds fail, TypeScript reports errors, or CI/CD pipelines break. Focuses on getting the build green fast.
STRIDE-based threat modeling for application architecture. Apply when designing new systems, reviewing architecture, or assessing security posture of existing applications.
Production-ready Docker patterns for multi-stage builds, security hardening, and orchestration. Apply when creating Dockerfiles, docker-compose configs, or deploying containerized applications.
Enforces Conventional Commits, PR standards, merge conflict resolution, and branch management. Apply when committing code, opening PRs, resolving conflicts, managing branches, or handling Git operations.
Deploy Node.js applications on Google Cloud with Cloud Run, Cloud Firestore, and Google APIs. Implement OAuth2 authentication and manage service accounts. Apply when building serverless applications, integrating Google services, or deploying to GCP.