{#-
    boilerplate/layout.html
    ~~~~~~~~~~~~~~~~~~~~~~~

    Master layout template for Tinkerer blog themes.

    :copyright: Copyright 2011-2018 by Vlad Riscutia and contributors (see
    CONTRIBUTORS file).
    :license: FreeBSD. Parts of this file are licensed under BSD license. See
    LICENSE file.
-#}

{#- Doctype -#}
{%- block doctype -%}
<!DOCTYPE html>
{%- endblock -%}

{%- set render_sidebar = (not embedded) and (not theme_nosidebar|tobool) and
                         (sidebars != []) -%}
{%- set url_root = pathto('', 1) -%} {#- link to root url (like: '#', '../../') #}
{%- if url_root == '#' -%}
    {%- set url_root = '' -%}
{%- endif -%}

{%- if not embedded and docstitle -%}
  {%- set titlesuffix = " &mdash; "|safe + docstitle|e -%}
{%- else -%}
  {%- set titlesuffix = "" -%}
{%- endif -%}

{%- set prevchar = prevchar is not defined and ' &laquo; ' or prevchar -%}
{%- set nextchar = nextchar is not defined and ' &raquo; ' or nextchar -%}
{%- set archivechar = archivechar is not defined and ' &mdash; ' or archivechar -%}

{%- if rss_service -%}
    {%- set rss_feed_link = rss_service -%}
{%- else -%}
    {%- set rss_feed_link = pathto('rss') -%}
{%- endif -%}

{%- set rss_in_page_nav = rss_in_page_nav is not defined or rss_in_page_nav -%}
{%- set rss_link_text = rss_link_text is not defined and None or rss_link_text -%}
{%- set rss_symbol = rss_symbol is not defined or rss_symbol -%}

{%- macro script() -%}
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '{{ url_root }}',
        VERSION:     '{{ release|e }}',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '{{ '' if no_search_suffix else file_suffix }}',
        SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}',
        HAS_SOURCE:  {{ has_source|lower }}
      };
    </script>
    {%- for scriptfile in script_files -%}
        {#- Hack to filter out jquery.js auto-included by Sphinx since jquery is
           already included in head. -#}
        {%- if "jquery" not in scriptfile.lower() -%}
            <script type="text/javascript" src="{{ pathto(scriptfile, 1) }}"></script>
        {%- endif -%}
    {%- endfor -%}
{%- endmacro -%}

{%- macro css() -%}
    {%- for cssfile in css_files -%}
    <link rel="stylesheet" href="{{ pathto(cssfile, 1) }}" type="text/css" />
    {%- endfor -%}
{%- endmacro -%}

{#- RSS link -#}
{%- macro rss_link() -%}
    <div class="rss">
        <a href="{{ rss_feed_link }}" title="Subscribe via RSS">
            {%- if rss_symbol -%}<span class="fa fa-lg fa-rss"></span>{%- endif -%}
            {% if rss_link_text -%}{{ rss_link_text }}{% endif -%}
        </a>
    </div>
{%- endmacro -%}

{#- prev/next -#}
{%- macro relbar() -%}
    {%- if prev or next -%}
        <ul class="related clearfix">
            <li class="left">
            {%- if prev -%}
                {{ prevchar }}<a href="{{ prev.link|e }}">{{ prev.title }}</a>
            {%- endif -%}
            </li>
            <li class="right">
            {%- if next -%}
                <a href="{{ next.link|e }}">{{ next.title }}</a>{{ nextchar }}
            {%- endif -%}
            </li>
        </ul>
    {%- endif -%}
{%- endmacro -%}

{#- Timestamp -#}
{%- macro timestamp(date) -%}
    {%- if date -%}
        <div class="timestamp postmeta">
            <span>{{ date }}</span>
        </div>
    {%- endif -%}
{%- endmacro -%}

{#- Author -#}
{%- macro author(author_name) -%}
    {%- if author_name -%}
        <div class="author">
            <span>{{ text_posted_by }} {{ author_name }}</span>
        </div>
    {%- endif -%}
{%- endmacro -%}

{#- Categories -#}
{%- macro category_list(post_categories) -%}
    {%- if post_categories -%}
        <div class="categories">
            <span>
                {{ text_filed_under }}:
                {% for link, category in post_categories -%}
                    <a href="{{ pathto('categories/' + link + '.html', 1) }}">{{ category }}</a>
                    {%- if not loop.last -%}, {% endif -%}
                {% endfor -%}
            </span>
        </div>
    {%- endif -%}
{%- endmacro -%}

{#- Tags -#}
{%- macro tag_list(post_tags) -%}
    {%- if post_tags -%}
        <div class="tags">
            <span>
                {{ text_tags }}:
                {% for link, tag in post_tags -%}
                    <a href="{{ pathto('tags/' + link + '.html', 1) }}">{{ tag }}</a>
                    {%- if not loop.last -%}, {% endif -%}
                {% endfor -%}
            </span>
        </div>
    {%- endif -%}
{%- endmacro -%}

{#- Comment count -#}
{%- macro comment_count(code) -%}
    {%- if code -%}
        <div class="comments">
            {{ code }}
        </div>
    {%- endif -%}
{%- endmacro -%}


{#- Post metadata -#}
{%- macro post_meta(metadata, comment_count_code=None) -%}
    <div class="postmeta">
        {{ author(metadata.author) }}
        {{ category_list(metadata.filing["categories"]) }}
        {{ tag_list(metadata.filing["tags"]) }}
        {{ comment_count(comment_count_code) }}
        {%- block post_meta_extra -%}{%- endblock -%}
    </div>
{%- endmacro -%}

{%- macro html_tag() -%}
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:og="http://ogp.me/ns#"
    xmlns:fb="https://www.facebook.com/2008/fbml"
{%- endmacro -%}

<!--[if lt IE 7]>      <html {{ html_tag() }} class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html {{ html_tag() }} class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html {{ html_tag() }} class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html {{ html_tag() }} class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="description" content="{{ description }}">
        <meta name="viewport" content="width=device-width">
        {{ metatags }}

        {%- block htmltitle -%}
             <title>{{ title|striptags|e }}{{ titlesuffix }}</title>
        {%- endblock %}

        {%- block css %}
            <link rel="stylesheet" href="{{ pathto('_static/normalize.css', 1) }}" type="text/css">
            <link rel="stylesheet" href="{{ pathto('_static/sphinx.css', 1) }}" type="text/css">
            <link rel="stylesheet" href="{{ pathto('_static/main.css', 1) }}" type="text/css">
            {%- if style not in ['none', 'main.css'] %}
            <link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css">
            {%- endif %}
            <link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
            <link rel="stylesheet" href="{{ pathto('_static/font-awesome.min.css', 1) }}" type="text/css">
        {%- endblock %}
        {{ css() }}
        {%- if not embedded -%}
        {%- if favicon -%}
        <link rel="shortcut icon" href="{{ pathto('_static/' + favicon, 1) }}" />
        {%- endif -%}

        {%- block headjs -%}
        <!-- Load modernizr and JQuery -->
        <script src="{{ pathto('_static/vendor/modernizr-2.6.2.min.js', 1) }}"></script>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="{{ pathto('_static/vendor/jquery-1.8.2.min.js', 1) }}"><\/script>')</script>
        <script src="{{ pathto('_static/plugins.js', 1) }}"></script>
        <script src="{{ pathto('_static/main.js', 1) }}"></script>
        {% endblock -%}

      {%- if use_opensearch -%}
        <link rel="search" type="application/opensearchdescription+xml"
              title="{% trans docstitle=docstitle|e -%}Search within {{ docstitle }}{% endtrans -%}"
              href="{{ pathto('_static/opensearch.xml', 1) }}"/>
        {%- endif -%}
        {%- endif -%}
      {%- block linktags -%}
        {%- if hasdoc('about') -%}
        <link rel="author" title="{{ _('About these documents') }}" href="{{ pathto('about') }}" />
        {%- endif -%}
        {%- if hasdoc('genindex') -%}
        <link rel="index" title="{{ _('Index') }}" href="{{ pathto('genindex') }}" />
        {%- endif -%}
        {%- if hasdoc('search') -%}
        <link rel="search" title="{{ _('Search') }}" href="{{ pathto('search') }}" />
        {%- endif -%}
        {%- if next -%}
        <link rel="next" title="{{ next.title|striptags|e }}" href="{{ next.link|e }}" />
        {%- endif -%}
        {%- if prev -%}
        <link rel="prev" title="{{ prev.title|striptags|e }}" href="{{ prev.link|e }}" />
        {%- endif -%}
        <link rel="alternate" type="application/rss+xml" title="RSS" href="{{ rss_feed_link }}" />
      {%- endblock -%}

      {%- if not embedded -%}
      {{ script() }}
      {%- endif -%}

      {%- block extrahead -%} {% endblock -%}
    </head>
    <body role="document">
        <!--[if lt IE 7]>
            <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
        <![endif]-->

      <div id="container">

      {%- block header -%}
          <header role="banner">
            <hgroup>
              <h1><a href="{{ pathto(pages[0][0]) }}">{{ shorttitle|e }}</a></h1>
              {%- if tagline -%}<h2>{{ tagline|e }}</h2>{%- endif -%}
            </hgroup>
          </header>
      {% endblock -%}

      {%- block navigation -%}
          <nav role="navigation">
            <ul>
              {%- block quicklinks -%}
                {%- if rss_in_page_nav -%}
                <li class="quicklink">{{ rss_link() }}</li>
                {%- endif -%}
              {%- endblock -%}
              {% for page in pages -%}
                <li class="main-nav">
                  <a href="{{ pathto(page[0]) }}">{{ page[1]|e }}</a>
                </li>
              {% endfor -%}
            </ul>
          </nav>
      {%- endblock -%}

          <div class="main-container" role="main">
      {%- block content -%}
            <div class="main wrapper body clearfix">
            {%- block document -%}
                  <article role="article">
                    {%- block relbar1 -%}{{ relbar() }}{% endblock -%}
                    {% block body -%} {% endblock -%}
                    {%- block relbar2 -%}{{ relbar() }}{% endblock -%}
                  </article>
            {%- endblock -%}
            {%- if render_sidebar -%}
              <aside class="sidebar">
                {%- if sidebars != None -%}
                  {%- for sidebartemplate in sidebars -%}
                  <section>
                    {%- include sidebartemplate -%}
                  </section>
                  {%- endfor -%}
                {%- endif -%}
              </aside>
            {%- endif -%}
            </div> <!-- #main -->
      {%- endblock -%}
          </div> <!-- #main-container -->

        <div class="footer-container" role="contentinfo">
      {%- block footer -%}
          <footer class="wrapper">
          {%- if show_copyright -%}
            {% trans copyright=copyright|e -%}&copy; Copyright {{ copyright }}. {% endtrans -%}
          {%- endif -%}
          {%- if show_sphinx -%}
            Powered by <a href="http://www.tinkerer.me/">Tinkerer</a> and <a href="http://sphinx.pocoo.org/">Sphinx</a>.
          {%- endif -%}
          </footer>
      {%- endblock -%}
        </div> <!-- footer-container -->

      </div> <!--! end of #container -->

        {#- Comment plug-in initialization -#}
        {%- if comment_enabler -%}{{ comment_enabler }}{%- endif -%}
        <!--[if lt IE 7 ]>
          <script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
          <script>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
        <![endif]-->
    </body>
</html>
