{#

YASS Macro

This macro is autoaded (thanks to jinja-macro-tags) and can use HTML like
tag to load the macros below. Refer to the docs.

We also recommend the HTML like tag

#}
{# -------------------------------------------------------------------------- #}
{# -------------------------------------------------------------------------- #}

{#  META  #}

{#: The basic meta tag :#}
{% macro meta_tag(name, value) %}
    <meta name="{{ name }}" content="{{ value or '' | safe }}">
{% endmacro %}

{#: Custom meta tag :#}
{% macro meta_custom(namespace, name, value) %}
    <meta {{ namespace }}="{{ name }}" content="{{ value or '' | safe }}">
{% endmacro %}

{#: opengraph property :#}
{% macro meta_property(namespace, name, value) %}
    <meta property="{{ namespace }}:{{ name }}" content="{{ value or '' | safe }}">
{% endmacro %}

{#: opengraph tag :#}
{% macro meta_opengraph(name, value) %}
    {% if value %}
        <meta property="og:{{ name }}" content="{{ value or '' | safe }}">
    {% endif %}
{% endmacro %}

{#: Custom meta tag :#}
{% macro meta_googleplus(name, value) %}
    {% if value %}
        <meta itemprop="{{ name }}" content="{{ value or '' | safe }}">
    {% endif %}
{% endmacro %}

{#: Custom meta tag :#}
{% macro meta_twitter(name, value) %}
    {% if value %}
        <meta name="twitter:{{ name }}" content="{{ value or '' | safe }}">
    {% endif %}
{% endmacro %}



{# -------------------------------------------------------------------------- #}

{#: Page meta_social_graph :#}
{% macro meta_social_graph() %}
    {% set url =  site.base_url + page.url %}
    {{ meta_opengraph("title", page.title or '') }}
    {{ meta_opengraph("description", page.description or '') }}
    {{ meta_opengraph("url", url) }}
    {{ meta_opengraph("site_name", site.name or '') }}
    {{ meta_opengraph("type", page.meta.object_type or 'article') }}
    {{ meta_googleplus("description", page.description or '' ) }}
    {{ meta_googleplus("name", page.title or '') }}
    {{ meta_googleplus("url", url) }}
    {{ meta_twitter("title", page.title or '') }}
    {{ meta_twitter("description", page.description or '') }}
    {{ meta_twitter("url", url ) }}

    {% if not page.image %}
        {{ meta_twitter("card", "summary") }}
    {% endif %}

    {% if page.image %}
        {{ meta_opengraph("image", page.image) }}
        {{ meta_googleplus("image", page.image) }}
        {{ meta_twitter("image", page.image) }}
        {{ meta_twitter("card", "summary_large_image") }}
    {% endif %}
{% endmacro %}

{#: Meta tags :#}
{% macro meta_tags() %}
    {% for k, v in page.meta.items() %}
        {{ meta_tag(k, v) }}
    {% endfor %}
{% endmacro %}

{#: Page title :#}
{% macro page_title(title=None, suffix=None, separator='|') %}
    <title>{{ title or page.title or '' }} {{ separator }} {{ suffix or site.name }}</title>
    {{ meta_tag('title', title or page.title or '') }}
    <link rel="canonical" href="{{ site.base_url }}"/>
{% endmacro %}

{#: Page description :#}
{% macro page_description(description=None) %}
    {{ meta_tag('description', description or page.description or site.description or '') }}
{% endmacro %}


{# -------------------------------------------------------------------------- #}
{# ASSETS #}

{#: CSS :#}
{% macro css(src) %}
    {% assets src %}
    <link rel="stylesheet" href="{{ ASSET_URL }}" type="text/css" >
    {% endassets %}
{% endmacro %}

{#: JS :#}
{% macro js(src) %}
    {% assets src %}
    <script type="text/javascript" src="{{ ASSET_URL }}"></script>
    {% endassets %}
{% endmacro %}

{#: IMG :#}
{% macro img(src, class="", id="") %}
    {% assets src %}
    <img src="{{ ASSET_URL }}" class="{{ class }}" id="{{ id }}"/>
    {% endassets %}
{% endmacro %}


{#: Favicon :#}
{% macro favicon(path) %}
    {% assets src %}
    <link rel="shortcut icon" href="{{ ASSET_URL }}">
    {% endassets %}
{% endmacro %}


{#: Favicon :#}
{% macro google_analytics(code=None) %}
    {% if not code %}
        {% set code = site.google_analytics %}
    {% 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 %}


{# PAGE_TOC: Table of Contents. It will include the TOC on the page #}
{% macro page_toc() %}
    {{ page.__toc__ }}
{% endmacro %}


{% macro timeago(dt, format="MM/DD/YYYY h:mm a") %}
    <time class="timeago" datetime="{{ dt }}">{{ dt | format_datetime(format) }}</time>
{% endmacro %}


{% macro datetime(dt, format="MM/DD/YYYY h:mm a") %}
    <span data-datetime="{{ dt }}" data-format="{{ format }}">{{ dt | format_datetime(format) }}</span>
{% endmacro %}


{% macro markdown() %}
    {{ caller() | markdown_to_html }}
{% endmacro %}

{% macro jade() %}
    {{ caller() | jade_to_html }}
{% endmacro %}

