All functions documented below are specific to Next.js projects and available via createNextBlogAIForNextJs
.
createNextBlogAIForNextJs
Initializes the Next-Blog-AI client for Next.js and returns API methods with Next.js-optimized cache support.
Function Signature
createNextBlogAIForNextJs(apiKey: string, defaultCacheOptions?: NextCacheOptions): { client, getBlogPosts, getBlogPost, getBlogPostSEO, getBlogListSEO, getAllBlogSlugs }
Input Parameters
Name | Type | Optional | Default Value | Description |
---|
apiKey | string | No | — | Your Next-Blog-AI API key. |
defaultCacheOptions | NextCacheOptions | Yes | | Default Next.js caching options (ISR, dynamic, etc.). |
revalidate | number | Yes | 0 | ISR seconds |
dynamic | boolean | Yes | false | Force dynamic rendering |
Return Parameters
Name | Type | Optional | Default Value | Description |
---|
client | object | No | — | The underlying API client. |
getBlogPosts | function | No | — | Fetch blog post list. |
getBlogPost | function | No | — | Fetch a single blog post. |
getBlogPostSEO | function | No | — | Fetch SEO metadata for a post. |
getBlogListSEO | function | No | — | Fetch SEO metadata for the blog list. |
getAllBlogSlugs | function | No | — | Fetch all blog slugs. |
Types & Interfaces
type NextCacheOptions = {
revalidate?: number; // ISR seconds
dynamic?: boolean; // Force dynamic rendering
}
Example Usage
import { createNextBlogAIForNextJs } from 'next-blog-ai';
const { getBlogPosts } = createNextBlogAIForNextJs(process.env.NEXT_BLOG_AI_API_KEY!);
const { data, error } = await getBlogPosts({ next: { revalidate: 3600 } }); // ISR: 1 hour
getBlogPosts
Fetch a paginated list of blog posts with Next.js cache control.
Function Signature
getBlogPosts(options?: NextBlogListOptions): Promise<ApiResponse<BlogListResponse>>
Input Parameters
Name | Type | Optional | Default Value | Description |
---|
options | NextBlogListOptions | Yes | | Options for pagination, format, and Next.js cache. |
page | number | Yes | | Page number |
perPage | number | Yes | | Posts per page |
format | 'html' | 'json' | Yes | 'html' | Response format |
display | 'grid' | 'list' | Yes | | Display type |
next | { revalidate?: number; dynamic?: boolean } | Yes | { revalidate: 0; dynamic: false } | Next.js cache options |
Return Parameters
Name | Type | Optional | Default Value | Description |
---|
data | BlogListResponse | No | — | Blog post list data. |
error | string | Yes | — | Error message, if any. |
Types & Interfaces
interface NextBlogListOptions {
page?: number;
perPage?: number;
format?: 'html' | 'json';
display?: 'grid' | 'list';
next?: { revalidate?: number; dynamic?: boolean };
}
// BlogListResponse is a union type based on format
type BlogListResponse = BlogListHtmlResponse | BlogListJsonResponse;
// HTML format response
interface BlogListHtmlResponse {
format: 'html';
content: string; // HTML content with inline styles
seo: SEOMetadata;
pagination: Pagination;
}
// JSON format response
interface BlogListJsonResponse {
format: 'json';
posts: BlogPostSummary[];
seo: SEOMetadata;
pagination: Pagination;
}
// Blog post summary for list views
interface BlogPostSummary {
id: string;
title: string;
slug: string;
excerpt: string;
featuredImageUrl?: string;
publishedAt: string;
readingTime: number;
commentCount: number;
language: string;
}
// Pagination information
interface Pagination {
totalPosts: number;
totalPages: number;
currentPage: number;
perPage: number;
}
Example Usage
const { data, error } = await nextBlogAI.getBlogPosts({
page: 1,
perPage: 10,
format: 'html',
next: { revalidate: 3600 },
});
getBlogPost
Fetch a single blog post with Next.js cache control.
Function Signature
getBlogPost(slug: string, options?: NextBlogPostOptions): Promise<ApiResponse<BlogPostResponse>>
Input Parameters
Name | Type | Optional | Default Value | Description |
---|
slug | string | No | — | The slug of the blog post to fetch. |
options | NextBlogPostOptions | Yes | | Options for format and Next.js cache. |
format | 'html' | 'json' | Yes | 'html' | Response format |
next | { revalidate?: number; dynamic?: boolean } | Yes | { revalidate: 0; dynamic: false } | Next.js cache options |
Return Parameters
Name | Type | Optional | Default Value | Description |
---|
data | BlogPostResponse | No | — | Blog post data. |
error | string | Yes | — | Error message, if any. |
Types & Interfaces
interface NextBlogPostOptions {
format?: 'html' | 'json';
next?: { revalidate?: number; dynamic?: boolean };
}
// BlogPostResponse is a union type based on format
type BlogPostResponse = BlogPostHtmlResponse | BlogPostJsonResponse;
// HTML format response
interface BlogPostHtmlResponse {
format: 'html';
content: string; // HTML content with inline styles
commentForm: string; // HTML for comment form
comments: string; // HTML for comments
seo: SEOMetadata;
}
// JSON format response
interface BlogPostJsonResponse {
format: 'json';
post: BlogPost;
comments: Comment[];
seo: SEOMetadata;
}
// Full blog post
interface BlogPost {
id: string;
title: string;
slug: string;
content: string;
excerpt: string;
featuredImageUrl?: string;
publishedAt: string;
readingTime: number;
language: string;
}
// Comment on a blog post
interface Comment {
id: string;
authorName: string;
content: string;
createdAt: string;
}
Example Usage
const { data, error } = await nextBlogAI.getBlogPost('my-post-slug', {
format: 'html',
next: { revalidate: 3600 },
});
getBlogPostSEO
Fetch SEO metadata for a blog post with Next.js cache control.
Function Signature
getBlogPostSEO(slug: string, options?: NextSEOOptions): Promise<ApiResponse<SEOResponse>>
Input Parameters
Name | Type | Optional | Default Value | Description |
---|
slug | string | No | — | The slug of the blog post to fetch SEO metadata for. |
options | NextSEOOptions | Yes | | Options for Next.js cache. |
Return Parameters
Name | Type | Optional | Default Value | Description |
---|
data | SEOResponse | No | — | SEO metadata for the blog post. |
error | string | Yes | — | Error message, if any. |
Types & Interfaces
interface NextSEOOptions {
next?: { revalidate?: number; dynamic?: boolean };
}
interface SEOResponse {
seo: SEOMetadata;
}
interface SEOMetadata {
title: string;
description: string;
keywords: string[];
structuredData: string | object;
featuredImage?: {
url: string;
alt: string;
};
}
Example Usage
const { data } = await nextBlogAI.getBlogPostSEO('my-post-slug', {
next: { revalidate: 3600 },
});
getBlogListSEO
Fetch SEO metadata for the blog list with Next.js cache control.
Function Signature
getBlogListSEO(options?: NextBlogListSEOOptions): Promise<ApiResponse<BlogListSEOResponse>>
Input Parameters
Name | Type | Optional | Default Value | Description |
---|
options | NextBlogListSEOOptions | Yes | | Options for Next.js cache. |
next | { revalidate?: number; dynamic?: boolean } | Yes | { revalidate: 0; dynamic: false } | Next.js cache options |
Return Parameters
Name | Type | Optional | Default Value | Description |
---|
data | BlogListSEOResponse | No | — | SEO metadata for the blog list. |
error | string | Yes | — | Error message, if any. |
Types & Interfaces
interface NextBlogListSEOOptions {
next?: { revalidate?: number; dynamic?: boolean };
}
interface BlogListSEOResponse {
seo: SEOMetadata;
}
Example Usage
const { data } = await nextBlogAI.getBlogListSEO({
next: { revalidate: 3600 },
});
getAllBlogSlugs
Fetch all blog slugs with Next.js cache control.
Function Signature
getAllBlogSlugs(options?: NextBlogSlugsOptions): Promise<ApiResponse<BlogSlugsResponse>>
Input Parameters
Name | Type | Optional | Default Value | Description |
---|
options | NextBlogSlugsOptions | Yes | | Options for Next.js cache. |
next | { revalidate?: number; dynamic?: boolean } | Yes | { revalidate: 0; dynamic: false } | Next.js cache options |
Return Parameters
Name | Type | Optional | Default Value | Description |
---|
data | BlogSlugsResponse | No | — | Array of blog slugs. |
error | string | Yes | — | Error message, if any. |
Types & Interfaces
interface NextBlogSlugsOptions {
next?: { revalidate?: number; dynamic?: boolean };
}
interface BlogSlugsResponse {
slugs: string[];
}
Example Usage
const { data } = await nextBlogAI.getAllBlogSlugs({
next: { revalidate: 600 },
});