Skip to content

Commit f129452

Browse files
committed
Add comments
1 parent 29436a4 commit f129452

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

samples/nextjs-cache-invalidation/src/app/[...slug]/page.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
// This page renders the date when it was built.
12
import { ShowElapsed } from '@/components/render-date';
23
import React from 'react';
34

45
export function generateStaticParams() {
5-
return [{ slug: ['en'] }];
6+
// Only pages with static params will be pre-rendered.
7+
// Change this array if you want to pre-render another path
8+
return [
9+
// Will pre-render the path /en:
10+
{ slug: ['en'] },
11+
12+
// Will pre-render the path /en/menu:
13+
// { slug: ['en', 'menu'] },
14+
];
615
}
716

817
export default function Page() {

samples/nextjs-cache-invalidation/src/app/webhook/route.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
// This file handles the endpoint "webhook", which handles incoming
2+
// webhook requests from Optimizely Graph
3+
//
4+
// For this example, when a content in a given path is modified and published,
5+
// the same path in this project is revalidated.
16
import { GraphClient } from '@optimizely/cms-sdk';
27
import { revalidatePath } from 'next/cache';
38

4-
// This GraphQL query fetches
9+
// With this GraphQL query, you can fetch the path of a document given its ID
510
const GET_PATH_QUERY = `
611
query GetPath($id:String) {
712
_Content(ids: [$id]) {
@@ -12,7 +17,6 @@ query GetPath($id:String) {
1217
}
1318
}`;
1419

15-
// Handles requests to the endpoint /webhook
1620
export async function POST(request: Request) {
1721
const body = await request.json();
1822
const docId = body.data.docId;
@@ -22,7 +26,8 @@ export async function POST(request: Request) {
2226
return Response.json({ message: 'docId is not a string' });
2327
}
2428

25-
// Transform "aaa-bbb-ccc_lang_state" to "aaabbbccc"
29+
// The field `docId` has the format <UUID>_<language>_status,
30+
// but to search in Graph, we need only the UUID without separation dashes `-`
2631
const id = docId.split('_')[0].replaceAll('-', '');
2732
const client = new GraphClient(process.env.OPTIMIZELY_GRAPH_SINGLE_KEY!, {
2833
graphUrl: process.env.OPTIMIZELY_GRAPH_URL,

samples/nextjs-cache-invalidation/src/components/render-date.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// This file contains a Client-side component.
2+
//
3+
// Given a `date` it renders the number of seconds elapsed from that time to the current time.
4+
// The "current time" is calculated from visitors browser.
15
'use client';
26
import { useEffect, useState } from 'react';
37

0 commit comments

Comments
 (0)