generateMeta.ts

1import { Metadata } from 'next'
2import { config } from '@/configs/main'
3
4type Meta = {
5	title: string
6	path?: string
7	description?: string
8	image?: string
9}
10
11export function generateMeta(meta: Meta): Metadata {
12	const baseUrl = config.url
13	const defaultDescription = `Personal information and projects of ${config.name}`
14	const defaultImage = `${baseUrl}/assets/images/cover.jpg` // Fallback image if meta.image is not provided
15
16	return {
17		title: `${meta.title} | ${config.name}`,
18		description: meta.description || defaultDescription,
19		authors: [
20			{
21				name: config.name,
22				url: `${baseUrl}/about`,
23			},
24		],
25		openGraph: {
26			title: `${meta.title} | ${config.name}`,
27			description: meta.description || defaultDescription,
28			url: `${baseUrl}${meta.path}`,
29			type: 'website',
30			locale: 'en_US',
31			siteName: config.name,
32			images: [
33				{
34					url: meta.image ? `${baseUrl}${meta.image}` : defaultImage,
35					width: 1200,
36					height: 630,
37					alt: meta.title,
38				},
39			],
40		},
41		twitter: {
42			card: 'summary_large_image',
43			title: `${meta.title} | ${config.name}`,
44			description: meta.description || defaultDescription,
45			images: [meta.image ? `${baseUrl}${meta.image}` : defaultImage],
46		},
47		robots: 'index, follow',
48		generator: 'Next.js',
49	}
50}
51