added header global
This commit is contained in:
23
utilities/getGlobals.ts
Normal file
23
utilities/getGlobals.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { Config } from 'src/payload-types';
|
||||
|
||||
import configPromise from '@payload-config';
|
||||
import { getPayload } from 'payload';
|
||||
import { unstable_cache } from 'next/cache';
|
||||
|
||||
type Global = keyof Config['globals']
|
||||
|
||||
async function getGlobal(slug: Global, depth = 0) {
|
||||
const payload = await getPayload({ config: configPromise })
|
||||
|
||||
const global = await payload.findGlobal({
|
||||
slug,
|
||||
depth,
|
||||
})
|
||||
|
||||
return global
|
||||
}
|
||||
|
||||
export const getCachedGlobal = (slug: Global, depth = 0) =>
|
||||
unstable_cache(async () => getGlobal(slug, depth), [slug], {
|
||||
tags: [`global_${slug}`],
|
||||
})
|
||||
Reference in New Issue
Block a user