import type { Metadata } from 'next'; import type { BlogArticle, BlogLocale } from './types'; import { absoluteUrl, articlePath, availableLocales, blogPath, indexingEnabled, translations } from './data'; import { copy } from './translations'; export function blogMetadata(locale: BlogLocale, article?: BlogArticle): Metadata { const title = article?.title ?? copy[locale].title; const description = article?.description ?? copy[locale].description; const path = article ? articlePath(article) : blogPath(locale); const variants = article ? translations(article).map(a => [a.locale, absoluteUrl(articlePath(a))]) : availableLocales().map(l => [l, absoluteUrl(blogPath(l))]); const languages = Object.fromEntries(variants); if (languages.en) languages['x-default'] = languages.en; return { metadataBase: new URL(absoluteUrl('/')), title: `${title} | STRATA`, description, robots: { index: indexingEnabled && (!article || article.published), follow: true }, alternates: { canonical: absoluteUrl(path), languages }, openGraph: { title, description, url: absoluteUrl(path), siteName: 'STRATA', type: article ? 'article' : 'website', locale, alternateLocale: variants.map(([l]) => l).filter(l => l !== locale), ...(article ? { modifiedTime: article.reviewedAt } : {}) }, twitter: { card: 'summary', title, description }, }; } export function articleSchema(article: BlogArticle) { const url = absoluteUrl(articlePath(article)); return [ { '@context': 'https://schema.org', '@type': 'Article', '@id': `${url}#article`, headline: article.title, description: article.description, inLanguage: article.locale, mainEntityOfPage: url, dateModified: article.reviewedAt, author: { '@type': 'Organization', name: 'STRATA', url: absoluteUrl('/') }, publisher: { '@type': 'Organization', name: 'STRATA', url: absoluteUrl('/') }, citation: article.sources.map(s => s.url) }, { '@context': 'https://schema.org', '@type': 'BreadcrumbList', itemListElement: [ { '@type': 'ListItem', position: 1, name: copy[article.locale].guides, item: absoluteUrl(blogPath(article.locale)) }, { '@type': 'ListItem', position: 2, name: article.title, item: url }, ] }, ]; }