From 31eedcd62da84d35943f48dbdc1aac76f86ae361 Mon Sep 17 00:00:00 2001 From: malewis5 Date: Thu, 6 Jun 2024 13:51:33 -0400 Subject: [PATCH 1/4] docs: remove preview secret. --- examples/cms-contentful/.env.local.example | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/cms-contentful/.env.local.example b/examples/cms-contentful/.env.local.example index eac50f166461e..4b0e3ac561ee6 100644 --- a/examples/cms-contentful/.env.local.example +++ b/examples/cms-contentful/.env.local.example @@ -1,5 +1,4 @@ CONTENTFUL_SPACE_ID= CONTENTFUL_ACCESS_TOKEN= CONTENTFUL_PREVIEW_ACCESS_TOKEN= -CONTENTFUL_PREVIEW_SECRET= CONTENTFUL_REVALIDATE_SECRET= \ No newline at end of file From 7d3bdf3c18ff0649ec0fc6df2796b1a156be4a7b Mon Sep 17 00:00:00 2001 From: malewis5 Date: Thu, 6 Jun 2024 13:51:50 -0400 Subject: [PATCH 2/4] feat: add contentful sdk --- .../cms-contentful/app/api/draft/route.ts | 23 +------------------ examples/cms-contentful/package.json | 1 + 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/examples/cms-contentful/app/api/draft/route.ts b/examples/cms-contentful/app/api/draft/route.ts index fb0d83fb20838..ba5f454abf582 100644 --- a/examples/cms-contentful/app/api/draft/route.ts +++ b/examples/cms-contentful/app/api/draft/route.ts @@ -1,22 +1 @@ -import { draftMode } from "next/headers"; -import { redirect } from "next/navigation"; -import { getPreviewPostBySlug } from "../../../lib/api"; - -export async function GET(request: Request) { - const { searchParams } = new URL(request.url); - const secret = searchParams.get("secret"); - const slug = searchParams.get("slug"); - - if (secret !== process.env.CONTENTFUL_PREVIEW_SECRET) { - return new Response("Invalid token", { status: 401 }); - } - - const post = await getPreviewPostBySlug(slug); - - if (!post) { - return new Response("Invalid slug", { status: 401 }); - } - - draftMode().enable(); - redirect(`/posts/${post.slug}`); -} +export { enableDraftHandler as GET } from "@contentful/vercel-nextjs-toolkit/app-router"; diff --git a/examples/cms-contentful/package.json b/examples/cms-contentful/package.json index 6f8cbac311b23..232212205ed96 100644 --- a/examples/cms-contentful/package.json +++ b/examples/cms-contentful/package.json @@ -9,6 +9,7 @@ "dependencies": { "@contentful/rich-text-react-renderer": "^15.17.1", "@contentful/rich-text-types": "^16.2.1", + "@contentful/vercel-nextjs-toolkit": "latest", "@tailwindcss/typography": "0.5.9", "@types/node": "^20.5.0", "@types/react": "^18.2.20", From 9a1cd356dbafbfcf23d1b9ec05f772f766d05580 Mon Sep 17 00:00:00 2001 From: malewis5 Date: Thu, 6 Jun 2024 14:02:57 -0400 Subject: [PATCH 3/4] fix: ignore to test build --- examples/cms-contentful/app/api/draft/route.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/cms-contentful/app/api/draft/route.ts b/examples/cms-contentful/app/api/draft/route.ts index ba5f454abf582..a89c2f3cd13d6 100644 --- a/examples/cms-contentful/app/api/draft/route.ts +++ b/examples/cms-contentful/app/api/draft/route.ts @@ -1 +1,2 @@ +//@ts-ignore export { enableDraftHandler as GET } from "@contentful/vercel-nextjs-toolkit/app-router"; From 750699a6b9e38bbbfbd1d48e6bb208bdf37dcc4e Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 20 Sep 2024 13:57:45 +0200 Subject: [PATCH 4/4] docs: fix the signature of CacheHandler#revalidateTag --- .../01-building-your-application/10-deploying/index.mdx | 6 ++++-- .../05-next-config-js/incrementalCacheHandlerPath.mdx | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/02-app/01-building-your-application/10-deploying/index.mdx b/docs/02-app/01-building-your-application/10-deploying/index.mdx index 2f410be3cba22..ed1944aa9fca3 100644 --- a/docs/02-app/01-building-your-application/10-deploying/index.mdx +++ b/docs/02-app/01-building-your-application/10-deploying/index.mdx @@ -175,11 +175,13 @@ module.exports = class CacheHandler { }) } - async revalidateTag(tag) { + async revalidateTag(tags) { + // tags is either a string or an array of strings + tags = [tags].flat() // Iterate over all entries in the cache for (let [key, value] of cache) { // If the value's tags include the specified tag, delete this entry - if (value.tags.includes(tag)) { + if (value.tags.some((tag) => tags.include(tag))) { cache.delete(key) } } diff --git a/docs/02-app/02-api-reference/05-next-config-js/incrementalCacheHandlerPath.mdx b/docs/02-app/02-api-reference/05-next-config-js/incrementalCacheHandlerPath.mdx index d134f44024649..ce3fc4abd16cf 100644 --- a/docs/02-app/02-api-reference/05-next-config-js/incrementalCacheHandlerPath.mdx +++ b/docs/02-app/02-api-reference/05-next-config-js/incrementalCacheHandlerPath.mdx @@ -39,9 +39,9 @@ Returns `Promise`. ### `revalidateTag()` -| Parameter | Type | Description | -| --------- | -------- | ---------------------------- | -| `tag` | `string` | The cache tag to revalidate. | +| Parameter | Type | Description | +| --------- | ---------------------- | ----------------------------- | +| `tag` | `string` or `string[]` | The cache tags to revalidate. | Returns `Promise`. Learn more about [revalidating data](/docs/app/building-your-application/data-fetching/caching-and-revalidating) or the [`revalidateTag()`](/docs/app/api-reference/functions/revalidateTag) function.