diff --git a/src/app/services/seo.service.ts b/src/app/services/seo.service.ts index 41456e7..37db090 100644 --- a/src/app/services/seo.service.ts +++ b/src/app/services/seo.service.ts @@ -86,6 +86,22 @@ export class SeoService { // Standard meta { name: 'description', content: description }, ]); + + this.setJsonLd({ + '@context': 'https://schema.org', + '@type': 'Product', + name: item.name, + description, + image: imageUrl, + url: itemUrl, + offers: { + '@type': 'Offer', + price: price.toFixed(2), + priceCurrency: item.currency || 'RUB', + availability: (item.quantity ?? 0) > 0 ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock', + url: itemUrl, + }, + }); } /** @@ -139,6 +155,30 @@ export class SeoService { // Remove product-specific tags this.meta.removeTag("property='product:price:amount'"); this.meta.removeTag("property='product:price:currency'"); + + this.setJsonLd({ + '@context': 'https://schema.org', + '@type': 'Organization', + name: this.siteName, + url: this.siteUrl, + ...(defaultImage ? { logo: defaultImage } : {}), + }); + } + + /** Replace (or remove, when data is null) the page's JSON-LD structured-data script tag. */ + private setJsonLd(data: Record | null): void { + const existing = this.doc.getElementById('seo-json-ld'); + existing?.remove(); + + if (!data) { + return; + } + + const script = this.doc.createElement('script'); + script.id = 'seo-json-ld'; + script.type = 'application/ld+json'; + script.text = JSON.stringify(data); + this.doc.head.appendChild(script); } private setOrUpdate(tags: Array<{ property?: string; name?: string; content: string }>): void {