Files
mypage/lib/seo.ts
2025-11-07 16:55:58 +02:00

34 lines
746 B
TypeScript

export interface SEOData {
title: string
description: string
url: string
image?: string
type?: 'website' | 'article'
author?: string
publishedTime?: string
}
export function generateStructuredData(data: SEOData) {
const structuredData: any = {
'@context': 'https://schema.org',
'@type': data.type === 'article' ? 'BlogPosting' : 'WebSite',
headline: data.title,
description: data.description,
url: data.url,
}
if (data.image) {
structuredData.image = data.image
}
if (data.type === 'article') {
structuredData.author = {
'@type': 'Person',
name: data.author || 'Unknown',
}
structuredData.datePublished = data.publishedTime
}
return JSON.stringify(structuredData)
}