{% macro image(src, alt=None, _class=None, style=None, width=None, height=None, link=None, link_class=None) -%}

  {% if link %}
    <a href='{{link}}'
      {% if link_class %} class='{{ link_class }}' {% endif %}
    >
  {% endif %}

  <img src='{{ src.path() }}'
     {% if alt %} alt='{{ alt }}' {% endif %}
     {% if _class %} class='{{ _class }}' {% endif %}
     {% if style %} style='{{ style }}' {% endif %}
     {% if width %} width='{{ width }}' {% endif %}
     {% if height %} height='{{ height }}' {% endif %}
   >

  {% if link %}
    </a>
  {% endif %}
{%- endmacro %}


{% macro google_analytics(page=None) -%}

  {% if page %}
    {% set code=page.ga_tracking_id %}
  {% else %}
    {% set code=site.config.get('/', 'ga_tracking_id') %}
  {% endif %}

  {% if code %}
  <script>
    (function (i, s, o, g, r, a, m) {
      i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
        (i[r].q = i[r].q || []).push(arguments)
      }, i[r].l = 1 * new Date(); a = s.createElement(o),
        m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

    ga('create', '{{ code }}', 'auto');
    ga('send', 'pageview');
  </script>
  {% endif %}

{%- endmacro %}


{% macro opengraph(page) -%}
<meta property="og:url" content="{{ page.url }}" />
<meta property="og:locale" content="{{ page.lang }}" />
<meta property="og:type" content="{{ page.og_type }}" />
{% set title = (page.og_title or page.title) | striptags %}
<meta property="og:title" content="{{ title }} - {{ page.site_title | striptags }}" />
{% set descr = (page.og_description or page.abstract) | striptags %}
{% if descr -%}
  <meta name="description" content="{{ descr }}"/>
  <meta property="og:description" content="{{ descr }}" />
{%- endif %}
{% if page.og_image -%}
<meta property="og:image" content="{{ page.load(page.og_image).url }}" />
{%- endif %}
{% if page.date -%}
<meta property="article:published_time" content="{{ page.date.isoformat() }}" />
{%- endif %}
{%- endmacro %}
