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();
}
function escapeHtml(str: string): string {
return str
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}