Files
manoon-headless/src/lib/seo/schema/breadcrumbSchema.ts
Unchained 234b1f1739 feat: comprehensive SEO system with keywords and schema markup
- Add 4-locale keyword configurations (SR, EN, DE, FR)
- Create schema generators (Product, Organization, Breadcrumb)
- Add React components for JSON-LD rendering
- Implement caching for keyword performance
- Abstract all SEO logic for maintainability
2026-03-30 11:22:44 +02:00

85 lines
2.3 KiB
TypeScript

import { BreadcrumbListSchema } from './types';
interface BreadcrumbItem {
name: string;
url?: string; // Optional for last item (current page)
}
/**
* Generate BreadcrumbList schema (JSON-LD)
* Pure function - takes breadcrumb items, returns schema object
*
* @param items - Array of breadcrumb items with name and optional URL
* @returns BreadcrumbListSchema object
* @example
* const breadcrumbs = [
* { name: 'Home', url: 'https://example.com' },
* { name: 'Products', url: 'https://example.com/products' },
* { name: 'Product Name' } // Current page (no URL)
* ];
* const schema = generateBreadcrumbSchema(breadcrumbs);
*/
export function generateBreadcrumbSchema(
items: BreadcrumbItem[]
): BreadcrumbListSchema {
return {
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
itemListElement: items.map((item, index) => ({
'@type': 'ListItem',
position: index + 1,
name: item.name,
...(item.url && { item: item.url }), // Only include item if URL exists
})),
};
}
/**
* Generate standard breadcrumbs for product pages
*
* @param baseUrl - Site base URL
* @param locale - Locale code
* @param productName - Product name
* @param productSlug - Product slug
* @returns BreadcrumbListSchema object
*/
export function generateProductBreadcrumbs(
baseUrl: string,
locale: string,
productName: string,
productSlug: string
): BreadcrumbListSchema {
const localePrefix = locale === 'sr' ? '' : `/${locale}`;
const items: BreadcrumbItem[] = [
{ name: 'Home', url: `${baseUrl}${localePrefix || '/'}` },
{ name: 'Products', url: `${baseUrl}${localePrefix}/products` },
{ name: productName }, // Current page
];
return generateBreadcrumbSchema(items);
}
/**
* Generate breadcrumbs for static pages
*
* @param baseUrl - Site base URL
* @param locale - Locale code
* @param pageName - Current page name
* @returns BreadcrumbListSchema object
*/
export function generatePageBreadcrumbs(
baseUrl: string,
locale: string,
pageName: string
): BreadcrumbListSchema {
const localePrefix = locale === 'sr' ? '' : `/${locale}`;
const items: BreadcrumbItem[] = [
{ name: 'Home', url: `${baseUrl}${localePrefix || '/'}` },
{ name: pageName }, // Current page
];
return generateBreadcrumbSchema(items);
}