Add configuration options for opening external links in new tab (#1360)

I've whipped up a solution that solves #1103. I've added a config option `nav_external_links_new_tab`, which is off by default. When turned on, it'll pop external nav links into a new tab. The idea was borrowed from how [aux_nav.html](https://github.com/just-the-docs/just-the-docs/blob/main/_includes/components/aux_nav.html) does it with `aux_links_new_tab`.

---------

Co-authored-by: Matt Wang <matt@matthewwang.me>
This commit is contained in:
CarbonNeuron
2023-10-04 14:10:56 -05:00
committed by GitHub
parent 2ccc451c2a
commit 33ba8d8eaa
4 changed files with 28 additions and 5 deletions

View File

@@ -4,7 +4,7 @@
Results in: HTML for the site-nav.
Includes:
components/nav.html
Overwrites:
Overwrites:
pages_top_size, collections_size, collection_entry,
collection_key, collection_value, collection.
{%- endcomment -%}
@@ -22,7 +22,11 @@
<ul class="nav-list">
{%- for node in site.nav_external_links -%}
<li class="nav-list-item external">
<a href="{{ node.url | absolute_url }}" class="nav-list-link external">
<a href="{{ node.url | absolute_url }}" class="nav-list-link external"
{% if node.opens_in_new_tab or (node.opens_in_new_tab == nil and site.nav_external_links_new_tab) %}
target="_blank" rel="noopener noreferrer"
{% endif %}
>
{{ node.title }}
{% unless node.hide_icon %}<svg viewBox="0 0 24 24" aria-labelledby="svg-external-link-title"><use xlink:href="#svg-external-link"></use></svg>{% endunless %}
</a>