Meta tags, sitemap, structured data, and SEO best practices
# SEO Optimization for Next.js with Google Antigravity
Master SEO optimization techniques for Next.js applications in your Google Antigravity projects. This guide covers metadata management, structured data, Core Web Vitals, and search engine best practices.
## Comprehensive Metadata Configuration
Set up dynamic metadata for all pages:
```typescript
// src/app/layout.tsx
import type { Metadata, Viewport } from "next";
export const viewport: Viewport = {
width: "device-width",
initialScale: 1,
maximumScale: 5,
themeColor: [
{ media: "(prefers-color-scheme: light)", color: "#ffffff" },
{ media: "(prefers-color-scheme: dark)", color: "#0a0a0a" },
],
};
export const metadata: Metadata = {
metadataBase: new URL("https://example.com"),
title: {
template: "%s | My Awesome App",
default: "My Awesome App - Build Amazing Products",
},
description: "The comprehensive platform for building and deploying modern web applications with AI-powered assistance.",
keywords: ["web development", "Next.js", "React", "TypeScript", "AI"],
authors: [{ name: "Your Company", url: "https://example.com" }],
creator: "Your Company",
publisher: "Your Company",
formatDetection: {
email: false,
address: false,
telephone: false,
},
openGraph: {
type: "website",
locale: "en_US",
url: "https://example.com",
siteName: "My Awesome App",
title: "My Awesome App - Build Amazing Products",
description: "The comprehensive platform for building and deploying modern web applications.",
images: [
{
url: "/og-image.png",
width: 1200,
height: 630,
alt: "My Awesome App Preview",
},
],
},
twitter: {
card: "summary_large_image",
title: "My Awesome App",
description: "Build amazing products with AI-powered assistance",
creator: "@yourhandle",
images: ["/twitter-image.png"],
},
robots: {
index: true,
follow: true,
googleBot: {
index: true,
follow: true,
"max-video-preview": -1,
"max-image-preview": "large",
"max-snippet": -1,
},
},
verification: {
google: "your-google-verification-code",
yandex: "your-yandex-verification-code",
},
alternates: {
canonical: "https://example.com",
languages: {
"en-US": "https://example.com",
"es-ES": "https://es.example.com",
},
},
};
```
## Dynamic Page Metadata
Generate metadata for dynamic routes:
```typescript
// src/app/blog/[slug]/page.tsx
import { Metadata } from "next";
import { notFound } from "next/navigation";
import { getPostBySlug, getAllPosts } from "@/lib/blog";
interface Props {
params: { slug: string };
}
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const post = await getPostBySlug(params.slug);
if (!post) {
return {
title: "Post Not Found",
};
}
const ogImage = post.coverImage || `/api/og?title=${encodeURIComponent(post.title)}`;
return {
title: post.title,
description: post.excerpt,
authors: [{ name: post.author.name }],
openGraph: {
type: "article",
title: post.title,
description: post.excerpt,
url: `https://example.com/blog/${params.slug}`,
images: [{ url: ogImage, width: 1200, height: 630 }],
publishedTime: post.publishedAt,
modifiedTime: post.updatedAt,
authors: [post.author.name],
tags: post.tags,
},
twitter: {
card: "summary_large_image",
title: post.title,
description: post.excerpt,
images: [ogImage],
},
};
}
export async function generateStaticParams() {
const posts = await getAllPosts();
return posts.map((post) => ({ slug: post.slug }));
}
export default async function BlogPost({ params }: Props) {
const post = await getPostBySlug(params.slug);
if (!post) notFound();
return (
<article>
<h1>{post.title}</h1>
<div dangerouslySetInnerHTML={{ __html: post.content }} />
</article>
);
}
```
## JSON-LD Structured Data
Add rich structured data for search engines:
```typescript
// src/components/StructuredData.tsx
interface ArticleSchema {
title: string;
description: string;
author: string;
publishedAt: string;
updatedAt?: string;
image: string;
url: string;
}
export function ArticleStructuredData({ data }: { data: ArticleSchema }) {
const schema = {
"@context": "https://schema.org",
"@type": "Article",
headline: data.title,
description: data.description,
image: data.image,
datePublished: data.publishedAt,
dateModified: data.updatedAt || data.publishedAt,
author: {
"@type": "Person",
name: data.author,
},
publisher: {
"@type": "Organization",
name: "My Awesome App",
logo: {
"@type": "ImageObject",
url: "https://example.com/logo.png",
},
},
mainEntityOfPage: {
"@type": "WebPage",
"@id": data.url,
},
};
return (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
/>
);
}
export function FAQStructuredData({ faqs }: { faqs: Array<{ question: string; answer: string }> }) {
const schema = {
"@context": "https://schema.org",
"@type": "FAQPage",
mainEntity: faqs.map((faq) => ({
"@type": "Question",
name: faq.question,
acceptedAnswer: {
"@type": "Answer",
text: faq.answer,
},
})),
};
return (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
/>
);
}
export function BreadcrumbStructuredData({ items }: { items: Array<{ name: string; url: string }> }) {
const schema = {
"@context": "https://schema.org",
"@type": "BreadcrumbList",
itemListElement: items.map((item, index) => ({
"@type": "ListItem",
position: index + 1,
name: item.name,
item: item.url,
})),
};
return (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
/>
);
}
```
## Dynamic Sitemap Generation
Create comprehensive sitemaps:
```typescript
// src/app/sitemap.ts
import { MetadataRoute } from "next";
import { getAllPosts } from "@/lib/blog";
import { getAllProducts } from "@/lib/products";
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const baseUrl = "https://example.com";
// Static pages
const staticPages: MetadataRoute.Sitemap = [
{ url: baseUrl, lastModified: new Date(), changeFrequency: "daily", priority: 1.0 },
{ url: `${baseUrl}/about`, lastModified: new Date(), changeFrequency: "monthly", priority: 0.8 },
{ url: `${baseUrl}/contact`, lastModified: new Date(), changeFrequency: "monthly", priority: 0.7 },
{ url: `${baseUrl}/pricing`, lastModified: new Date(), changeFrequency: "weekly", priority: 0.9 },
];
// Dynamic blog posts
const posts = await getAllPosts();
const blogPages: MetadataRoute.Sitemap = posts.map((post) => ({
url: `${baseUrl}/blog/${post.slug}`,
lastModified: new Date(post.updatedAt),
changeFrequency: "weekly",
priority: 0.7,
}));
// Dynamic products
const products = await getAllProducts();
const productPages: MetadataRoute.Sitemap = products.map((product) => ({
url: `${baseUrl}/products/${product.slug}`,
lastModified: new Date(product.updatedAt),
changeFrequency: "daily",
priority: 0.8,
}));
return [...staticPages, ...blogPages, ...productPages];
}
```
## Core Web Vitals Optimization
Optimize for performance metrics:
```typescript
// src/components/OptimizedImage.tsx
import Image from "next/image";
interface OptimizedImageProps {
src: string;
alt: string;
width: number;
height: number;
priority?: boolean;
}
export function OptimizedImage({ src, alt, width, height, priority = false }: OptimizedImageProps) {
return (
<Image
src={src}
alt={alt}
width={width}
height={height}
priority={priority}
loading={priority ? "eager" : "lazy"}
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
placeholder="blur"
blurDataURL="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD..."
/>
);
}
```
Google Antigravity generates comprehensive SEO implementations that maximize search visibility through proper metadata, structured data, and performance optimization.This SEO prompt is ideal for developers working on:
By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their seo implementations.
Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.
This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.
You can modify the prompt by adding specific requirements, constraints, or preferences. For SEO projects, consider mentioning your framework version, coding style, and any specific libraries you're using.