Fix external links for sites with no pages (#1021)

Fix #1020

- Move the display of nav external links from `_includes/nav.html` to `_layouts/default.html`.
- Replace ` unless include.key` by `if site.nav_external_links`.
- Wrap the body of `if site.nav_external_links` in `<ul class="nav-list">…</ul>`.

To test this PR:

1.  Add to `_config.yml`:
    ```yaml
    defaults:
      -
        scope: {path: ""}
        values: {nav_exclude: true}
    ```

2.  Check that the only link to appear in the nav panel is external.

Co-authored-by: Matt Wang <matt@matthewwang.me>
This commit is contained in:
Peter Mosses 2022-11-05 08:35:37 +01:00 committed by GitHub
parent bf6f5028af
commit 29b5d14789
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -207,17 +207,6 @@
</li>
{%- endunless -%}
{%- endfor -%}
{%- unless include.key -%}
{%- assign nav_external_links = site.nav_external_links -%}
{%- for node in nav_external_links -%}
<li class="nav-list-item external">
<a href="{{ node.url | absolute_url }}" class="nav-list-link external">
{{ 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>
</li>
{%- endfor -%}
{%- endunless -%}
</ul>
{%- comment -%}

View File

@ -58,6 +58,18 @@ layout: table_wrappers
{% if pages_top_size > 0 %}
{% include nav.html pages=site.html_pages key=nil %}
{% endif %}
{%- if site.nav_external_links -%}
<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">
{{ 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>
</li>
{%- endfor -%}
</ul>
{%- endif -%}
{% if site.just_the_docs.collections %}
{% assign collections_size = site.just_the_docs.collections | size %}
{% for collection_entry in site.just_the_docs.collections %}