{% block seo %}

{% if page.meta.title %}
<title>{{ page.meta.title }}</title>
{% else %}
<title>{{ page.title }}</title>
{% endif %}

{% if page.meta.description %}
<meta name="description" content="{{ page.meta.description }}">
{% endif %}

{% if page.meta.keywords %}
<meta name="keywords" content="{{ page.meta.keywords }}">
{% endif %}

{% if page.meta.author %}
<meta name="author" content="{{ page.meta.author }}">
{% endif %}

{% if page.canonical_url %}
<link rel="canonical" href="{{ page.canonical_url }}">
{% endif %}

<!-- Open Graph (Facebook, LinkedIn) -->
{% if page.meta.title %}
<meta property="og:title" content="{{ page.meta.title }}">
{% else %}
<meta property="og:title" content="{{ page.title }}">
{% endif %}

{% if page.meta.description %}
<meta property="og:description" content="{{ page.meta.description }}">
{% endif %}

{% if page.canonical_url %}
<meta property="og:url" content="{{ page.canonical_url }}">
{% endif %}

{% if page.meta.image %}
<meta property="og:image" content="{{ page.meta.image }}">
{% endif %}

{% if site_name %}
<meta property="og:site_name" content="{{ site_name }}">
{% endif %}

<!-- Twitter Card -->
{% if page.meta.title %}
<meta name="twitter:title" content="{{ page.meta.title }}">
{% else %}
<meta name="twitter:title" content="{{ page.title }}">
{% endif %}

{% if page.meta.description %}
<meta name="twitter:description" content="{{ page.meta.description }}">
{% endif %}

{% if page.meta.image %}
<meta name="twitter:image" content="{{ page.meta.image }}">
{% endif %}

<!-- JSON-LD Structured Data -->
{% if page.meta.title and page.meta.description %}
<script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "Article",
    "headline": "{% if page.meta.title %}{{ page.meta.title }}{% else %}{{ page.title }}{% endif %}",
    "url": "{{ page.canonical_url }}",
    "description": "{{ page.meta.description }}",
    {% if page.meta.author %}
    "author": {
      "@type": "Person",
      "name": "{{ page.meta.author }}"
    },
    {% endif %}
    {% if site_name %}
    "publisher": {
      "@type": "Organization",
      "name": "{{ site_name }}",
      {% if page.meta.image %}
      "logo": {
        "@type": "ImageObject",
        "url": "{{ page.meta.image }}"
      }
      {% endif %}
    },
    {% endif %}
    {% if page.meta.date %}
    "datePublished": "{{ page.meta.date }}",
    {% endif %}
    {% if page.canonical_url %}
    "mainEntityOfPage": {
      "@type": "WebPage",
      "@id": "{{ page.canonical_url }}"
    },
    {% endif %}
    {% if page.meta.image %}
    "image": {
      "@type": "ImageObject",
      "url": "{{ page.meta.image }}",
      "width": 1200,
      "height": 630
    }
    {% endif %}
  }
  </script>
{% endif %}

{% endblock seo %}