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

{#  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 %}

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

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

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

{#
Create a page title
#}
{% macro meta_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 %}

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


{#
Create page description
#}
{% macro meta_page_description(description=None) %}
    {{ meta_tag('description', description or page.description or site.description or '') }}
{% endmacro %}


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

{#
Create a CSS stylesheet
#}
{% 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 %}

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

{#: IMAGE :#}
{% macro image(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 %}

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

{% 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 datetime="{{ dt }}" class="timeago yass-time-ago" >{{ dt | format_datetime(format) }}</time>
{% endmacro %}

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

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

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

{% macro year() %}
    <time datetime="{{ __YASS__.YEAR }}" class="yass-current-year">{{ __YASS__.YEAR }}</time>
{% endmacro %}

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

{% macro current_year() %}
    <time datetime="{{ __YASS__.YEAR }}" >{{ __YASS__.YEAR }}</time>
{% endmacro %}

{# -------------------------------------------------------------------------- #}
{#
    Creates a link to a page
    page: the name, ie: index.jade
    text: the text to create the link. If empty, it will use the link original text
    title: the link title.
    class: a class
    id: id
#}
{% macro link_to(page, text=None, title=None, class="", id="") %}
    {{ page | yass_link_to(text=text, title=title, _class=class, id=id) | safe }}
{% endmacro %}

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

{% macro url_to(page) %}
    {{ page | yass_url_to }}
{% endmacro %}

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

{% macro static_link(src, text, title=None, class="", id="") %}
    {% assets src %}
    <a href="{{ ASSET_URL }}" class="{{ class }}" title="{{ title }}" id="{{ id }}">{{ text | safe}}</a>
    {% endassets %}
{% endmacro %}

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

{% macro static_url(src) %}
    {%- assets src %}
        {{ ASSET_URL }}
    {% endassets -%}
{% endmacro %}

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


{% macro include(file) %}
    {% include file %}
{% endmacro %}

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

{% macro embed(url, witdh="100%", height="480", class="", id="") %}
    <a href={{ url }} class="oembed {{ class }}" id="{{ id }}" data-max-width="{{ width}}" data-max-height="{{ height }}"></a>
{% endmacro %}



{#
paginator
     :prev: Text for previous button
     :next: Text for Next button
     :class: A class name for pagination if customed. If you are extending the class
             best to add the original class and your custom class
             ie: 'pagination my_custom_pagination' or 'pager my_custom_page'
     :pager: If true it will show a pager instead of numbered pagination
     :mobile: if True, if will show the pagination into a 'pager'

#}
{% macro paginator(prev="Prev", next="Next", class=None, pager=False, mobile=True) %}
    {% if mobile %}
        <div class="hidden-lg hidden-md hidden-sm">
            {{ _pagination(prev, next, class, pager=true, **kwargs) }}
        </div>
        <div class="hidden-xs">
            {{ _pagination(prev, next, class, pager=false, **kwargs) }}
        </div>
    {% else %}
        {{ _pagination(prev, next, class, pager, **kwargs) }}
    {% endif %}

{% endmacro %}

{%- macro _pagination_page_url(page_num) -%}
{{- page.paginator.slug | replace("{page_num}", page_num) | safe -}}
{%- endmacro -%}

{% macro _pagination(prev="", next="", class=None, pager=False) %}

    {{ kwargs }}

    {%  if not class %}
        {% set class = "pagination" %}
        {% if pager %}
            {% set class = "pager" %}
        {% endif %}
    {% endif %}

    {% set _prev_btn = "<span aria-hidden='true'>&larr;</span> %s" % prev %}
    {% set _next_btn = "%s <span aria-hidden='true'>&rarr;</span>" % next %}

    <nav>
      <ul class="{{ class }}">

          {%- if page.paginator.has_prev %}
            <li class="previous">
                <a href="{{ _pagination_page_url(page.paginator.prev_page_number) }}" >
                    {{ _prev_btn | safe }}
                </a>
            </li>
          {% else %}
            <li class="disabled previous">
                <a href="#">{{ _prev_btn | safe }}</a>
            </li>
          {%- endif %}

            {% if not pager %}
                  {%- for page_num in page.paginator.iter_pages() %}
                    {% if page_num %}
                      {% if page_num != page.paginator.page %}
                        <li><a href="{{ _pagination_page_url(page_num) }}"
                         rel="me">{{ page_num }}</a></li>
                      {% else %}
                        <li class="active"><span>{{ page_num }}</span></li>
                      {% endif %}
                    {% else %}
                      <li><span class="ellipsis">...</span></li>
                    {% endif %}
                  {%- endfor %}
            {% endif %}

          {%- if page.paginator.has_next %}
            <li class="next">
                <a href="{{ _pagination_page_url(page.paginator.next_page_number) }}">
                    {{ _next_btn | safe }}
                </a>
            </li>
          {% else %}
            <li class="disabled next">
                <a href="#">{{ _next_btn | safe }}</a>
            </li>
          {%- endif %}
      </ul>
    </nav>

{% endmacro %}

