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

* Support defining LINKS that open in the same window
This commit is contained in:
Fidel Ramos 2019-11-01 08:38:10 +00:00 committed by Alexandre Vicenzi
parent 0490ead40f
commit d97d5a586d

View file

@ -107,17 +107,30 @@
{% if pages or LINKS %} {% if pages or LINKS %}
<nav> <nav>
<ul class="list"> <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 -%} {% if PAGES_SORT_ATTRIBUTE -%}
{% set pages = pages|sort(attribute=PAGES_SORT_ATTRIBUTE) %} {% set pages = pages|sort(attribute=PAGES_SORT_ATTRIBUTE) %}
{%- endif %} {%- endif %}
{% if DISPLAY_PAGES_ON_MENU %} {% if DISPLAY_PAGES_ON_MENU %}
{% for page in pages %} {% 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 %} {% endfor %}
{% endif %} {% endif %}
{% for name, link in LINKS %} {% 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 %} {% endfor %}
</ul> </ul>
</nav> </nav>