Files
supabase/apps/cms/src/utilities/generateMeta.ts
T
Francesco SansalvadoreandIvan Vasilov 7e91d7c4a3 fix cms types and build (#36145)
* fix cms types and build

---------

Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2025-08-11 17:44:38 +02:00

48 lines
1.2 KiB
TypeScript

import type { Metadata } from 'next'
import type { Media, Post, Config } from '../payload-types'
import { mergeOpenGraph } from './mergeOpenGraph.ts'
import { getServerSideURL } from './getURL.ts'
const getImageURL = (image?: Media | Config['db']['defaultIDType'] | null) => {
const serverUrl = getServerSideURL()
let url = serverUrl + '/website-template-OG.webp'
if (image && typeof image === 'object' && 'url' in image) {
const ogUrl = image.sizes?.og?.url
url = ogUrl ? serverUrl + ogUrl : serverUrl + image.url
}
return url
}
export const generateMeta = async (args: { doc: Partial<Post> | null }): Promise<Metadata> => {
const { doc } = args
const ogImage = getImageURL(doc?.meta?.image)
const title = doc?.meta?.title
? doc?.meta?.title + ' | Payload Website Template'
: 'Payload Website Template'
return {
description: doc?.meta?.description,
openGraph: mergeOpenGraph({
description: doc?.meta?.description || '',
images: ogImage
? [
{
url: ogImage,
},
]
: undefined,
title,
url: Array.isArray(doc?.slug) ? doc?.slug.join('/') : '/',
}),
title,
}
}