Resolve common content generation issues and optimize your blog output
When the API returns content not found errors for your blog requests.
Error: Blog post not found
Common Causes:
Solutions:
// Get all available blog slugs
const { data, error } = await nextBlogAI.getAllBlogSlugs();
console.log(data.slugs); // Array of available slugsWhen the content format doesn't match what your application expects.
Solutions:
// For HTML format
const { data } = await nextBlogAI.getBlogPost(slug, {
format: 'html' // Returns pre-rendered HTML
});
// For JSON format
const { data } = await nextBlogAI.getBlogPost(slug, {
format: 'json' // Returns structured data for custom rendering
});const nextBlogAI = createNextBlogAI({
apiKey: process.env.NEXT_BLOG_AI_API_KEY!,
defaultFormat: 'html' // 'html' or 'json'
});<div dangerouslySetInnerHTML={{ __html: data.content }} />Content seems to be fetched successfully but isn't displaying on your website.
Common Causes:
Solutions:
const nextBlogAI = createNextBlogAI({
apiKey: process.env.NEXT_BLOG_AI_API_KEY!,
styles: {
blogContent: `
/* Your custom CSS for blog posts */
.blog-post h1 {
font-size: 2.5rem;
}
.blog-post p {
margin-bottom: 1.5rem;
}
`,
blogList: `
/* Your custom CSS for blog listings */
.blog-list-item {
margin-bottom: 2rem;
}
`
}
});Implement caching
// With Next.js cache settings
const { data } = await nextBlogAI.getBlogPosts({
next: {
revalidate: 3600 // Cache for 1 hour
}
});
// With client's built-in cache
const { data } = await nextBlogAI.getBlogPosts({
cache: {
ttl: 3600 // Cache for 1 hour
}
});Use ISR for blog pages
// In page.tsx
export const revalidate = 3600; // Revalidate every hour
export default async function BlogPage() {
const { data } = await nextBlogAI.getBlogPosts();
return <BlogList posts={data.posts} />;
}Generate metadata for SEO
// In app/blog/[slug]/page.tsx
import { Metadata } from 'next';
import { nextBlogAI } from '@/lib/blog-api';
export async function generateMetadata({
params
}: {
params: Promise<{ slug: string }>
}): Promise<Metadata> {
const { slug } = await params;
const { data } = await nextBlogAI.getBlogPostSEO(slug);
return {
title: data.title,
description: data.description,
keywords: data.keywords,
openGraph: {
title: data.title,
description: data.description,
images: [{
url: data.featuredImage
}]
}
};
}For more control over your content and performance, consider these advanced configuration options:
Configure automatic retry behavior for resilience against temporary failures:
const nextBlogAI = createNextBlogAI({
apiKey: process.env.NEXT_BLOG_AI_API_KEY!,
retry: {
maxRetries: 3, // Maximum number of retry attempts
initialDelay: 300, // Initial delay before first retry (ms)
backoffFactor: 2, // Factor by which to increase delay after each retry
maxDelay: 10000, // Maximum delay between retries (ms)
jitter: true, // Whether to add randomness to retry delays
}
});Control how blog lists are displayed:
// Set default display format when initializing client
const nextBlogAI = createNextBlogAI({
apiKey: process.env.NEXT_BLOG_AI_API_KEY!,
defaultBlogListDisplay: 'grid', // 'grid' or 'list'
});
// Override for specific requests
const { data } = await nextBlogAI.getBlogPosts({
display: 'list', // Override default display format
});Generate all available blog post slugs for dynamic routes:
// In app/blog/[slug]/page.tsx
import { nextBlogAI } from '@/lib/blog-api';
// Generate dynamic routes at build time
export async function generateStaticParams() {
const { data } = await nextBlogAI.getAllBlogSlugs();
return data.slugs.map((slug) => ({
slug,
}));
}If you're still experiencing problems with content generation, please contact our support team.