-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateMetadata.ts
51 lines (44 loc) · 1.58 KB
/
generateMetadata.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import type { Metadata } from 'next/types';
type CustomMetadata = {
title?: string;
description?: string;
keywords?: string[];
date?: string;
}
/**
* Generates metadata for a website.
*
* @param {CustomMetadata} metadata - Custom metadata to be added to the generated metadata.
* @returns {Metadata} The generated metadata object.
*/
export default function generateMetadata(metadata: CustomMetadata = {}): Metadata {
const generatedMetadata: Metadata = {
metadataBase: new URL('https://skyhan.cloud'),
openGraph: {
title: 'skyhan.cloud',
type: 'website',
locale: 'en_US',
url: 'https://skyhan.cloud',
images: [
{
url: '/og.png',
width: 960,
height: 540
}
]
}
};
if (metadata.title) generatedMetadata.title = `${metadata.title} - skyhan.cloud`;
else generatedMetadata.title = 'skyhan.cloud';
if (metadata.description) {
generatedMetadata.description = metadata.description;
generatedMetadata.openGraph!.description = metadata.description;
} else {
generatedMetadata.description = 'My personal blog and portfolio website where I share my projects and thoughts on various topics.';
generatedMetadata.openGraph!.description = 'My personal blog and portfolio website where I share my projects and thoughts on various topics.';
}
if (metadata.keywords) generatedMetadata.keywords = metadata.keywords;
else generatedMetadata.keywords = ['personal', 'blog', 'portfolio', 'projects'];
if (metadata.date) generatedMetadata.date = metadata.date;
return generatedMetadata;
}