Next.js App Router
Fetch and render SiteLift articles as static pages in your Next.js 13+ App Router application using our official SDK.
The official Next.js integration for SiteLift. Seamlessly connect your Next.js App Router project to your SiteLift dashboard and render lightning-fast, SEO-optimized blog articles directly from the server.
This package comes equipped with a lightweight, zero-dependency client and an intuitive CLI tool to scaffold a ready-to-use blog structure into your codebase within seconds. View on npm
Quick Start
Get up and running with the Next.js App Router integration in minutes.
Installation
Add the package to your project using npm, pnpm, or yarn:
npm install @getsitelift/nextjs-blog(Note: Requires Node.js 18.17+ and a Next.js App Router setup)
Configuration
Locate your API key in the SiteLift dashboard (Settings → Integrations → Next.js Blog). Store the key securely in your .env.local file:
SITELIFT_BLOG_API_KEY=your_api_key_hereWarning
NEXT_PUBLIC_.Scaffold Your Blog (Recommended)
Want to skip the manual setup? Use our built-in CLI to instantly generate a clean, unstyled blog architecture right inside your Next.js application.
Run the following command at the root of your project:
npx @getsitelift/nextjs-blog initNeed it in a specific folder? Pass the path: npx @getsitelift/nextjs-blog init src/app. Use --force if you need to overwrite an existing blog directory.
Built-in Routes from the CLI
When you use the init command, you get the following structure out of the box:
| Path | Purpose |
|---|---|
| /blog | The main archive displaying all your published articles. |
| /blog/[slug] | The dedicated article page, complete with server-side rendering, JSON-LD schema injection, and metadata tags for optimal SEO. |
| /blog/sitemap.xml | An auto-updating sitemap to keep search engines informed. |
Post-Scaffold Checklist
Verify Installation
Make sure @getsitelift/nextjs-blog is in your package.json.
Environment Variable
Double-check that SITELIFT_BLOG_API_KEY is present in your .env.local.
Image Domains
Allow external images by updating your next.config.ts (or next.config.js):
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
images: {
remotePatterns: [{ protocol: "https", hostname: "*" }],
},
};
export default nextConfig;Start Developing: Run npm run dev and navigate to /blog to see your articles in action!
Manual Integration
If you prefer to build the pages yourself, it's just as simple. Instantiate the BlogClient in a utility file and fetch data directly in your Server Components.
1. Create the Client
import { BlogClient } from "@getsitelift/nextjs-blog";
export const siteLiftBlog = new BlogClient({
apiKey: process.env.SITELIFT_BLOG_API_KEY,
revalidate: 86400, // Caches responses for 24 hours
});2. List Articles
import { siteLiftBlog } from "@/lib/sitelift";
import Link from "next/link";
export default async function BlogArchive() {
const articles = await siteLiftBlog.listArticles();
return (
<section>
<h1>Our Latest Articles</h1>
{articles.map((article) => (
<article key={article.id}>
<Link href={`/blog/${article.slug}`}>
<h2>{article.title}</h2>
</Link>
</article>
))}
</section>
);
}3. Render a Single Article
import { siteLiftBlog } from "@/lib/sitelift";
import { notFound } from "next/navigation";
export default async function ArticleView({ params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params;
const article = await siteLiftBlog.getArticleBySlug(slug);
if (!article) return notFound();
return (
<main>
{/* Article content includes Title and Featured Image */}
<div dangerouslySetInnerHTML={{ __html: article.contentHtml || "" }} />
{/* Display Tags */}
{article.tags && <p className="leading-loose">Tags: {article.tags.join(", ")}</p>}
</main>
);
}Data Caching & Next.js ISR
This package is designed to work harmoniously with Next.js Incremental Static Regeneration (ISR).
Default Caching
The CLI starter defaults to revalidate: 86400 (24 hours) to ensure blazing-fast load times.
Cache Invalidation
While updates in the SiteLift dashboard instantly clear our edge cache, Next.js will serve its cached version until the revalidation window expires.
Always Fresh Data
Want real-time data? Pass revalidate: false to the BlogClient options to trigger a cache: 'no-store' behavior.
BlogClient API Reference
Available Methods
| Method | Returns | Description |
|---|---|---|
| listArticles() | Promise<BlogArticleSummary[]> | Retrieves a paginated list of published articles. |
| getAllArticles() | Promise<BlogArticleSummary[]> | Automatically paginates and returns all published articles. |
| getArticleBySlug(slug) | Promise<BlogArticle | null> | Retrieves the complete content and metadata for a specific article slug. |
| getArticleById(id) | Promise<BlogArticle | null> | Retrieves the complete content and metadata for a specific article by its UUID. |
| getArticleBySlugAndMarkPublished(slug) | Promise<BlogArticle | null> | Retrieves an article by slug and simultaneously marks its status as published. |
| getSitemapEntries() | Promise<BlogSitemapEntry[]> | Returns lightweight data perfect for building sitemap.xml. |
Available Article Fields
When you fetch an article, you have access to a rich set of data: