teqo-backup/src/utilities/documents.ts
Francisco Ignácio Fontoura Solla b955c48091 feat(cms): add homepage global and wire frontend to Payload content
- add  global () with required media upload field
- register new global in  and include it in admin live preview
- replace hardcoded frontend landing content with CMS-driven homepage image
- add typed cached utilities for globals/documents + centralized revalidation helpers
- migrate components to new global utility module and remove deprecated  helper
- update  revalidation hook to use shared global revalidation
- refine frontend layout/header and simplify legacy homepage CSS
- regenerate  for new global/schema changes
2026-02-15 16:19:57 -03:00

32 lines
964 B
TypeScript

import { Config } from '@/payload-types'
import configPromise from '@payload-config'
import { revalidateTag } from 'next/cache'
import { unstable_cache } from 'next/cache'
import { getPayload } from 'payload'
type Collection = keyof Config['collections']
export const getDocumentById = <Slug extends Collection>(
collection: Slug,
id: string,
depth?: number,
) =>
getPayload({ config: configPromise }).then((payload) =>
payload.findByID({ collection, id, depth }),
)
const getTag = <Slug extends Collection>(collection: Slug, id: string) =>
`document_${collection}:${id}`
export const getCachedDocumentById = <Slug extends Collection>(
collection: Slug,
id: string,
depth?: number,
) =>
unstable_cache(() => getDocumentById(collection, id, depth), [id], {
tags: [getTag(collection, id)],
})
export const revalidateDocumentById = <Slug extends Collection>(collection: Slug, id: string) =>
revalidateTag(getTag(collection, id))