mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 15:13:07 +00:00
- 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
32 lines
964 B
TypeScript
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))
|