{% set blog = page.find(header_var('blog_url')|defined(theme_var('blog_page'))) %}
{% set new_base_url = blog.url == '/' ? '' : blog.url %}

{% if uri.params %}
    {% set feed_url = blog.url == '/' or blog.url == base_url_relative ? (uri.uri~'/'~blog.slug) : blog.url %}
{% else %}
    {% set feed_url = blog.url == '/' or blog.url == base_url_relative ? (base_url_relative~'/'~blog.slug) : blog.url %}
{% endif %}

<section id="menu">
  <div style="padding: 1.5em;"><a class="close" href="#menu" title="Menu"></a></div>
  {% if config.plugins.simplesearch.enabled and icon_search %}
    <!-- Search -->
    <section>
      {% include 'partials/simplesearch_searchbox_sidebar.html.twig' %}
    </section>
  {% endif %}
  <!-- Links -->
  <div id="sidebarmenu">
    {% include 'partials/sidebar_navigation.html.twig' %}
  </div>
  {% if config.plugins.archives.enabled and archives_data is not empty %}
    <!-- Archives -->
    <div class="sidebar-content">
      <header>
        <h3>{{ 'FUTURE.SIDEBAR.ARCHIVES.HEADLINE'|t }}</h3>
      </header>
      {% include 'partials/archives.html.twig' with {'base_url': new_base_url} %}
    </div>
  {% endif %}
  {% if config.plugins.relatedpages.enabled and related_pages|length > 0 %}
  <!-- Related posts -->
    <div class="sidebar-content">
      <header>
        <h3>{{ 'FUTURE.SIDEBAR.RELATED_POSTS.HEADLINE'|t }}</h3>
      </header>
      {% include 'partials/relatedpages.html.twig' %}
    </div>
  {% endif %}
  {% if config.plugins.taxonomylist.enabled %}
    {% set taxlist = children_only is defined ? taxonomylist.getChildPagesTags() : taxonomylist.get() %}
    {% if taxlist %}
    <!-- Taxonomy list -->
      <div class="sidebar-content">
        <header>
          <h3>{{ 'FUTURE.SIDEBAR.TAGS.HEADLINE'|t }}</h3>
        </header>
        {% include 'partials/taxonomylist.html.twig' with {'base_url':new_base_url, 'taxonomy':'tag'} %}
      </div>
    {% endif %}
  {% endif %}
  {% if config.plugins.feed.enabled %}
  <!-- Syndicate -->
    <div class="sidebar-content">
      <header>
        <h3>{{ 'FUTURE.SIDEBAR.SYNDICATE.HEADLINE'|t }}</h3>
      </header>
        <ul class="actions start">
        <li><a href="{{ feed_url }}.atom"><i class="fa fa-rss-square"></i> Atom 1.0</a></li>
        <li><a href="{{ feed_url }}.rss"><i class="fa fa-rss-square"></i> RSS</a></li>
        {% if config.plugins.feed.enable_json_feed %}<li><a href="{{ feed_url }}.json"><i class="fa fa-rss-square"></i> JSON</a></li>{% endif %}
        </ul>
    </div>
  {% endif %}
  {% if icon_lang and config.plugins.langswitcher.enabled and system.languages.supported is not null %}
  <!-- Langswitcher -->
  <div class="sidebar-content lang start">
    <header>
      <h3>{{ 'FUTURE.SIDEBAR.LANGSWITCHER.HEADLINE'|t }}</h3>
    </header>
    <ul class="actions start">
      {% include 'partials/langswitcher.html.twig' %}
    </ul>
  </div>
  {% endif %}
  {% if config.plugins.login.enabled and icon_login%}
  <!-- Login button -->
    <div>
      <ul class="actions stacked">
      {% if not grav.user.authenticated %}
        <li><a href="{{ base_url_absolute }}{{config.plugins.login.route}}" class="button large fit">{{ 'PLUGIN_LOGIN.BTN_LOGIN'|t }}</a></li>
      {% else %}
        <li>Logged as: <strong>{{ grav.user.fullname ?: grav.user.username }}</strong></li>
        <li><a class="button large fit" href="{{ url(uri.addNonce((uri.path)|trim('/') ~ '/task' ~ config.system.param_sep ~ 'login.logout', 'logout-form', 'logout-nonce'))|e }}">{{ 'PLUGIN_LOGIN.BTN_LOGOUT'|t }}</a></li>
      {% endif %}
      </ul>
    </div>
  {% endif %}
</section>
