{# --- social/meta_product.html --- #} {# Context expected: site, d (Product), request #} {# Visibility → robots: index unless soft-deleted #} {% set robots_here = 'noindex,nofollow' if d.deleted_at else 'index,follow' %} {# Compute canonical #} {% set _site_url = site().url.rstrip('/') if site and site().url else '' %} {% set _product_path = request.path if request else ('/products/' ~ (d.slug or '')) %} {% set canonical = _site_url ~ _product_path if _site_url else (request.url if request else None) %} {# Include common base (charset, viewport, robots default, RSS, Org/WebSite JSON-LD) #} {% set robots_override = robots_here %} {% include 'social/meta_base.html' %} {# ---- Titles / descriptions ---- #} {% set base_product_title = d.title or base_title %} {% set og_title = base_product_title %} {% set tw_title = base_product_title %} {# Description: prefer short, then HTML stripped #} {% set desc_source = d.description_short or (d.description_html|striptags if d.description_html else '') %} {% set description = (desc_source|trim|replace('\n',' ')|replace('\r',' ')|striptags)|truncate(160, True, '…') %} {# ---- Image priority: product image, then first gallery image, then site default ---- #} {% set image_url = d.image or ((d.images|first).url if d.images and (d.images|first).url else None) or (site().default_image if site and site().default_image else None) %} {# ---- Price / offer helpers ---- #} {% set price = d.special_price or d.regular_price or d.rrp %} {% set price_currency = d.special_price_currency or d.regular_price_currency or d.rrp_currency %} {# ---- Basic meta ---- #} {{ base_product_title }} {% if canonical %}{% endif %} {# ---- Open Graph ---- #} {% if canonical %}{% endif %} {% if image_url %}{% endif %} {# Optional product OG price tags #} {% if price and price_currency %} {% endif %} {% if d.brand %} {% endif %} {% if d.sku %} {% endif %} {# ---- Twitter ---- #} {% if site and site().twitter_site %}{% endif %} {% if image_url %}{% endif %} {# ---- JSON-LD Product ---- #} {% set jsonld = { "@context": "https://schema.org", "@type": "Product", "name": d.title, "image": image_url, "description": description, "sku": d.sku, "brand": d.brand, "url": canonical } %} {# Brand as proper object if present #} {% if d.brand %} {% set jsonld = jsonld | combine({ "brand": { "@type": "Brand", "name": d.brand } }) %} {% endif %} {# Offers if price available #} {% if price and price_currency %} {% set jsonld = jsonld | combine({ "offers": { "@type": "Offer", "price": price, "priceCurrency": price_currency, "url": canonical, "availability": "https://schema.org/InStock" } }) %} {% endif %}