mirror of
https://github.com/supabase/supabase.git
synced 2026-10-18 07:39:07 +03:00
* fix cms types and build --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
48 lines
1.2 KiB
TypeScript
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,
|
|
}
|
|
}
|