~/posts/daily-log-notion-cms-isr-revalidation.mdx
MDX • UTF-8
cd .. (Back to Explorer)
READ_MODE: ACTIVE
2 min read
Daily Engineering Log: Otomasi Pipeline Notion CMS & ISR Revalidation
Catatan teknis harian mengenai integrasi headless CMS Notion API 2025-09-03 dengan on-demand Incremental Static Regeneration di Next.js App Router.
#Daily Log
#Next.js
#Notion API
#Automation
#DevOps
Hari ini fokus pada sinkronisasi pipeline data antara headless CMS berbasis Notion API dengan static site renderer Next.js menggunakan arsitektur On-Demand Incremental Static Regeneration (ISR).
1. Konteks Masalah & Kebutuhan
Saat mengelola portofolio dan publikasi artikel teknis secara dinamis:
- Evolusi API Notion: Transisi ke API versi
2025-09-03mengubah struktur entitas database menjadidata_sourcedengan penanganan properti yang lebih ketat. - Cache Invalidation: Memastikan perubahan konten di Notion langsung ter-render di Vercel tanpa perlu melakukan redeploy penuh dari git repository.
- Standardisasi Skema: Menyeragamkan key properties (slug, tags, coverImage, markdown body) agar parsing MDX berjalan mulus.
2. Implementasi Webhook / API Revalidation Handler
Berikut pola handler Next.js API Route untuk memvalidasi secret token dan mengeksekusi revalidatePath:
Contoh Route Handler:
import { NextRequest } from "next/server";
import { revalidatePath } from "next/cache";
import { getPosts, getProjects } from "@/lib/contents";
export async function POST(req: NextRequest) {
const secret = req.headers.get("secret");
if (secret !== process.env.REVALIDATE_SECRET) {
return new Response("Unauthorized", { status: 401 });
}
const posts = await getPosts();
const projects = await getProjects();
// Revalidate index dan individual dynamic pages
revalidatePath("/");
revalidatePath("/post");
revalidatePath("/project");
posts.forEach(p => revalidatePath(`/post/${p.meta.slug}`));
projects.forEach(p => revalidatePath(`/project/${p.meta.slug}`));
return Response.json({
status: "success",
revalidated: { posts: posts.length, projects: projects.length }
});
}3. Catatan Teknis & Workflow
Lesson Learned: Selalu pisahkan antara data fetcher caching layer (
revalidate: 3600) dengan instant purge tag agar performa First Byte (TTFB) tetap berada di bawah 80ms.
4. Metrik Hasil Integrasi
| Parameter | Sebelum Otomasi | Sesudah Otomasi | Peningkatan |
|---|---|---|---|
| Waktu Publikasi | 3-5 menit (Git commit & build) | < 1 detik (API Call) | Instant Sync |
| Beban Server / CI | High (Vercel Build Minutes) | Zero (Cache Purge Only) | 100% Hemat Quota |
| Data Consistency | Rentan Desinkronisasi | Real-time via Notion API | Akurat |