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
export interface OpenGraphData {
title: string;
description: string;
image: string;
url: string;
type?: string;
}
export function generateOpenGraphTags(data: OpenGraphData): string {
const { title, description, image, url, type = "website" } = data;
return `
<meta property="og:title" content="${escapeHtml(title)}" />
<meta property="og:description" content="${escapeHtml(description)}" />
<meta property="og:image" content="${escapeHtml(image)}" />
<meta property="og:type" content="${escapeHtml(type)}" />
<meta property="og:url" content="${escapeHtml(url)}" />
`.trim();
}
// Helper function to escape HTML special characters
function escapeHtml(str: string): string {
return str
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
// Usage example:
// const ogData: OpenGraphData = {
// title: "The Breakfast Bandit",
// description:
// "In a 24-hour detention, five misfit teens join forces to sneak a runaway truckload of breakfast burritos past a relentless sheriff who has them in his sights. As they navigate their differences and forge unlikely friendships, they discover that fre
// image: "https://fal.media/files/zebra/6tOPoTCgnrC83g6MK9Wbo.jpeg",
// url: "[Your URL here]",
// };
// console.log(generateOpenGraphTags(ogData));