Next-Blog-AI
Home/Documentation/Styling & SEO/SEO Optimization
Back to Documentation

SEO Optimization

Optimize your Next-Blog-AI content for search engines

Next-Blog-AI provides several features to help optimize your blog content for search engines. This guide covers the key SEO optimization techniques you can implement with Next-Blog-AI.

Sitemap Generation

Generate a dynamic sitemap for your blog posts using Next.js sitemap.ts and Next-Blog-AI's getAllBlogSlugs function:

// src/app/sitemap.ts
import type { MetadataRoute } from 'next';
import { createNextBlogAIForNextJs } from 'next-blog-ai';

const { getAllBlogSlugs, getBlogPostSEO } = createNextBlogAIForNextJs(process.env.NEXT_BLOG_AI_API_KEY!);

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const { data, error } = await nextBlogAI.getAllBlogSlugs({
    next: {
      cache: 'force-cache',
    },
  });

  if (error || !data) {
    return [];
  }

  const sitemap = data.slugs.map((slug) => ({
    url: `your-sass-app.com/blog/${slug}`,
    lastModified: new Date(),
    changeFrequency: 'daily' as const,
    priority: 0.9,
  }));

  return [
    {
      url: 'your-sass-app.com/',
      lastModified: new Date(),
      changeFrequency: 'weekly',
      priority: 1.0,
    },
    {
      url: 'your-sass-app.com/blog',
      lastModified: new Date(),
      changeFrequency: 'daily',
      priority: 0.9,
    },
    ...sitemap,
  ];
}

This generates a complete sitemap that includes all your blog posts, ensuring search engines can discover and index your content.

Metadata Optimization

Combine these techniques with Next-Blog-AI's SEO metadata functions for a comprehensive SEO strategy:

// In your blog post page
export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const { slug } = await params;

  // Use the SEO-only function for metadata
  const { data, error } = await nextBlogAI.getBlogPostSEO(slug, {
    cache: {
      ttl: 3600, // Cache for 1 hour
    },
  });

  if (error || !data) {
    return {
      title: 'Blog Post | Your Site',
      description: 'Read our latest article',
    };
  }

  // Create complete metadata object
  const metadata: Metadata = {
    title: data.seo.title,
    description: data.seo.description,
    keywords: data.seo.keywords.join(', '),
  };

  // Add OpenGraph and Twitter card metadata
  const extendedSeo = data.seo as ExtendedSEOMetadata;
  if (extendedSeo.featuredImage) {
    metadata.openGraph = {
      images: [
        {
          url: extendedSeo.featuredImage.url,
          width: 1200,
          height: 630,
          alt: extendedSeo.featuredImage.alt,
        },
      ],
    };

    metadata.twitter = {
      card: 'summary_large_image',
      images: [extendedSeo.featuredImage.url],
    };
  }

  return metadata;
}

Best Practices for SEO

In addition to using Next-Blog-AI's built-in SEO features, consider these best practices:

  • Use semantic HTML - Next-Blog-AI's HTML output follows semantic HTML best practices
  • Optimize image alt text - All images provided by Next-Blog-AI include proper alt text
  • Implement schema markup - Next-Blog-AI includes BlogPosting schema automatically
  • Focus on page speed - Static generation and proper caching improve performance
  • Create internal links - Next-Blog-AI automatically links related content

Performance Monitoring

Monitor the SEO performance of your Next-Blog-AI content using:

  • Google Search Console
  • Core Web Vitals measurements
  • Lighthouse scores
  • Analytics for tracking user engagement