Skip to content
Permalink
Browse files

Support defining LINKS that open in the same window (#185)

* Support defining LINKS that open in the same window
  • Loading branch information...
haplo authored and alexandrevicenzi committed Nov 1, 2019
1 parent 0490ead commit d97d5a586d28245a70d42c8ca8c9f23f49b0f9c7
Showing with 15 additions and 2 deletions.
  1. +15 −2 templates/base.html
@@ -107,17 +107,30 @@ <h1><a href="{{ SITEURL }}">{{ SITETITLE }}</a></h1>
{% if pages or LINKS %}
<nav>
<ul class="list">
{# Open links in new window depending on the LINKS_IN_NEW_TAB setting #}
{% macro get_target(link) -%}
{%- if LINKS_IN_NEW_TAB is not defined -%}
_blank
{%- elif LINKS_IN_NEW_TAB in ('all', none, true) -%}
_blank
{%- elif LINKS_IN_NEW_TAB == "external" and not link.startswith("/") and not link.startswith(SITEURL) -%}
_blank
{%- else -%}
_self
{%- endif -%}
{%- endmacro %}

{% if PAGES_SORT_ATTRIBUTE -%}
{% set pages = pages|sort(attribute=PAGES_SORT_ATTRIBUTE) %}
{%- endif %}
{% if DISPLAY_PAGES_ON_MENU %}
{% for page in pages %}
<li><a href="{{ SITEURL }}/{{ page.url }}{% if not DISABLE_URL_HASH %}#{{ page.slug }}{% endif %}">{{ page.title }}</a></li>
<li><a target="{{ get_target(SITEURL) }}" href="{{ SITEURL }}/{{ page.url }}{% if not DISABLE_URL_HASH %}#{{ page.slug }}{% endif %}">{{ page.title }}</a></li>
{% endfor %}
{% endif %}

{% for name, link in LINKS %}
<li><a href="{{ link }}" target="_blank">{{ name }}</a></li>
<li><a target="{{ get_target(link) }}" href="{{ link }}" >{{ name }}</a></li>
{% endfor %}
</ul>
</nav>

0 comments on commit d97d5a5

Please sign in to comment.
You can’t perform that action at this time.