feat: parseAcfLink
This commit is contained in:
18
wp-content/themes/moonshine/app/utils/acf-link.ts
Normal file
18
wp-content/themes/moonshine/app/utils/acf-link.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import * as z from "zod";
|
||||
import type { AcfLinkFragment } from "#graphql/operations";
|
||||
|
||||
const acfLinkSchema = z.object({
|
||||
title: z.string(),
|
||||
url: z.string(),
|
||||
target: z.string().optional().default(""),
|
||||
});
|
||||
export type AcfLinkOutput = z.infer<typeof acfLinkSchema>;
|
||||
|
||||
export function parseAcfLink(data?: Partial<AcfLinkFragment>) {
|
||||
try {
|
||||
return acfLinkSchema.parse(data);
|
||||
}
|
||||
catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user