LINKS_IN_NEW_TAB setting

This setting can be modified to open all LINKS in the same window,
open all LINKS in a new window or only only external links in new
windows.
This commit is contained in:
Fidel Ramos 2019-10-27 14:09:43 +00:00
parent 56a2a32974
commit 2455759bd8
No known key found for this signature in database
GPG key ID: 64490E0A752C21C4
2 changed files with 15 additions and 3 deletions

View file

@ -39,6 +39,12 @@ USE_FOLDER_AS_CATEGORY = False
MAIN_MENU = True MAIN_MENU = True
HOME_HIDE_TAGS = True HOME_HIDE_TAGS = True
# Valid values for LINKS_IN_NEW_TAB:
# * Unset, None, True or any string to open all LINKS in a new window (default)
# * 'no', 'none', False or 0 to open all LINKS in the same window
# * 'external' to open LINKS to external sites in a new window, internal links in same window
LINKS_IN_NEW_TAB = 'external'
SOCIAL = ( SOCIAL = (
('github', 'https://github.com/alexandrevicenzi/Flex'), ('github', 'https://github.com/alexandrevicenzi/Flex'),
('rss', '/blog/feeds/all.atom.xml'), ('rss', '/blog/feeds/all.atom.xml'),

View file

@ -107,18 +107,24 @@
{% 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 link_target(link) -%}
{% if LINKS_IN_NEW_TAB not in ('no', 'none', false, 0, 'external') or (LINKS_IN_NEW_TAB == "external" and not link.startswith("/") and not link.startswith(SITEURL)) %}
target="_blank"
{% 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 {{ link_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 %}
{# Open external links in new window, relative links in the same window #} <li><a {{ link_target(link) }} href="{{ link }}" >{{ name }}</a></li>
<li><a href="{{ link }}" {% if link[0] != '/' and not link.startswith(SITEURL) %}target="_blank"{% endif %}>{{ name }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</nav> </nav>