diff --git a/app/(public)/[...slug]/page.tsx b/app/(public)/[...slug]/page.tsx index 669da843..fba2c742 100644 --- a/app/(public)/[...slug]/page.tsx +++ b/app/(public)/[...slug]/page.tsx @@ -14,6 +14,7 @@ import {getMenu} from "@/lib/drupal/get-menu"; import {isDraftMode} from "@/lib/drupal/is-draft-mode"; import UnpublishedBanner from "@/components/patterns/unpublished-banner"; import {getPathFromContext} from "@/lib/drupal/utils"; +import {cache} from "react"; export const revalidate = false; @@ -23,7 +24,7 @@ class RedirectError extends Error { } } -const fetchNodeData = async (params: Params): Promise<{ node: StanfordNode, fullWidth: boolean }> => { +const fetchNodeData = cache(async (params: Params): Promise<{ node: StanfordNode, fullWidth: boolean }> => { const draftMode = isDraftMode(); const path = getPathFromContext({params}); const valid = await pathIsValid(path) @@ -56,9 +57,11 @@ const fetchNodeData = async (params: Params): Promise<{ node: StanfordNode, full (node?.type === 'node--sul_library' && node.layout_selection?.resourceIdObjMeta?.drupal_internal__target_id === 'sul_library_full_width'); return {node, fullWidth} -} +}) export const generateMetadata = async ({params}: PageProps): Promise => { + if (isDraftMode()) return {}; + try { const {node} = await fetchNodeData(params); if (!node) return {}; diff --git a/app/(public)/page.tsx b/app/(public)/page.tsx index 17f59c48..f37b5f0b 100644 --- a/app/(public)/page.tsx +++ b/app/(public)/page.tsx @@ -7,7 +7,7 @@ import {ParagraphRows} from "@/components/paragraph/rows/rows"; import fetchComponents from "@/lib/fetch-components"; import {notFound} from "next/navigation"; -export const revalidate = 1800; +export const revalidate = false; export const generateMetadata = async (): Promise => { const node = await getResourceByPath('/'); diff --git a/src/lib/drupal/get-menu.tsx b/src/lib/drupal/get-menu.tsx index 9c9c8f4e..c9d681a5 100644 --- a/src/lib/drupal/get-menu.tsx +++ b/src/lib/drupal/get-menu.tsx @@ -16,7 +16,6 @@ export const getMenu = async( const url = buildUrl(`/jsonapi/menu_items/${name}`) const response = await fetch(url.toString(), { - next: {revalidate: 86400}, headers: await buildHeaders(options), }) diff --git a/src/lib/drupal/get-resource.tsx b/src/lib/drupal/get-resource.tsx index 0734f06e..6f71fae3 100644 --- a/src/lib/drupal/get-resource.tsx +++ b/src/lib/drupal/get-resource.tsx @@ -4,20 +4,7 @@ import {buildUrl, buildHeaders, getJsonApiPathForResourceType, getPathFromContex import {deserialize} from "@/lib/drupal/deserialize"; import {JsonApiParams} from "next-drupal"; import {PageProps} from "@/lib/drupal/drupal"; - -export const getResources = async ( - items: { type: string, id: string }[], - draftMode: boolean = false -): Promise => { - const requests: PromiseLike[] = []; - items.map(item => requests.push(getResource(item.type, item.id, {draftMode}))); - - // @ts-ignore - return Promise.all(requests.map((p, i): T => p.catch((e: unknown) => { - console.error(`Failed Fetching (probably unpublished) component ${items[i].type}-${items[i].id}`, e); - return null - }))); -} +import {cache} from "react"; export const getResourceFromContext = async ( type: string, @@ -54,7 +41,7 @@ export const getResourceFromContext = async ( return resource } -export const getResourceByPath = async ( +export const getResourceByPath = cache(async ( path: string, options?: { accessToken?: AccessToken @@ -86,7 +73,7 @@ export const getResourceByPath = async ( ] const url = buildUrl("/subrequests", {_format: "json"}) - console.log('subrequest path', JSON.stringify(path)); + console.log('subrequest path', path); let response = await fetch(url.toString(), { next: options.next, @@ -122,7 +109,7 @@ export const getResourceByPath = async ( if (data.errors) throw new Error(data.errors[0].detail) return options.deserialize ? deserialize(data) : data -} +}) export const getResourceCollection = async ( type: string,