## -*- coding: utf-8 -*-

<%def name="meta_translations(post)">
    %if len(translations) > 1:
        %for langname in sorted(translations):
            %if langname != lang and post.is_translation_available(langname):
                <link rel="alternate" hreflang="${langname}" href="${post.permalink(langname)[:-5]}">
            %endif
        %endfor
    %endif
</%def>

<%def name="html_tags(post)">
    %if post.tags:
        <ul itemprop="keywords" class="tags">
        %for tag in post.tags:
          % if tag not in hidden_tags:
            <li><a class="tag p-category" href="${_link('tag', tag)}" rel="tag">${tag}</a></li>
          % endif
        %endfor
        </ul>
    %endif
</%def>

<%def name="html_pager(post)">
    %if post.prev_post or post.next_post:
        <ul class="pager hidden-print">
        %if post.prev_post:
            <li class="previous">
                <a href="${post.prev_post.permalink()[:-5]}" rel="prev" title="${post.prev_post.title()|h}"><i class="fa fa-fw fa-chevron-left"></i> ${messages("Previous post")}</a>
            </li>
        %endif
        %if post.next_post:
            <li class="next">
                <a href="${post.next_post.permalink()[:-5]}" rel="next" title="${post.next_post.title()|h}">${messages("Next post")} <i class="fa fa-fw fa-chevron-right"></i></a>
            </li>
        %endif
        </ul>
    %endif
</%def>

<%def name="open_graph_metadata(post)">
%if use_open_graph:
    <meta property="og:site_name" content="${blog_title|striphtml}">
    <meta property="og:title" content="${post.title()[:70]|h}">
    <meta property="og:url" content="${abs_link(permalink[:-5])}">
    %if post.description():
    <meta property="og:description" content="${post.description()[:200]|h}">
    %else:
    <meta property="og:description" content="${post.text(strip_html=True)[:200]|h}">
    %endif
    %if post.previewimage:
    <meta property="og:image" content="${url_replacer(permalink[:-5], post.previewimage, lang, 'absolute')}">
    %endif
    <meta property="og:type" content="article">
### Will only work with Pintrest and breaks everywhere else who expect a [Facebook] URI.
###    %if post.author():
###    <meta property="article:author" content="${post.author()}">
###    %endif
    %if post.date.isoformat():
    <meta property="article:published_time" content="${post.formatted_date('webiso')}">
    %endif
    %if post.tags:
        %for tag in post.tags:
           <meta property="article:tag" content="${tag}">
        %endfor
    %endif
%endif
</%def>

<%def name="twitter_card_information(post)">
%if twitter_card and twitter_card['use_twitter_cards']:
    <meta name="twitter:card" content="${twitter_card.get('card', 'summary')|h}">
    %if 'site:id' in twitter_card:
    <meta name="twitter:site:id" content="${twitter_card['site:id']}">
    %elif 'site' in twitter_card:
    <meta name="twitter:site" content="${twitter_card['site']}">
    %endif
    %if 'creator:id' in twitter_card:
    <meta name="twitter:creator:id" content="${twitter_card['creator:id']}">
    %elif 'creator' in twitter_card:
    <meta name="twitter:creator" content="${twitter_card['creator']}">
    %endif
%endif
</%def>

<%def name="mathjax_script(post)">
    <% has_math = getattr(post, 'has_math', False) %>
    %if has_math:
        <script type="text/x-mathjax-config">
        MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex ','$'], ['\\(','\\)']]}});</script>
        <script src="/assets/js/mathjax.js"></script>
    %endif
</%def>

