Skip to content

Commit

Permalink
fix: Ensure seamless navigation between primary and auxiliary sites
Browse files Browse the repository at this point in the history
This commit addresses issues where navigating between internal pages and those
hosted on an auxiliary site would open additional tabs. The following key changes
have been introduced:

1. **Setting the top-level `url` configuration** to match the auxiliary site’s
   actual URL. This ensures:
   - Links to the download site are treated as internal, preventing unnecessary
     new tab openings.
   - Various `<meta>` elements, as well as generated files such as `browserconfig.xml`,
     `robots.txt`, and `sitemap.xml`, correctly reference `https://download.slicer.org`
     instead of `https://slicer.org`.

2. **Introducing the `is_primary_site` config variable** to differentiate between
   the primary site (`slicer.org`) and auxiliary sites (e.g., `download.slicer.org`).
   This variable is now used in the `header`, `navbar-column`, and `sitemap-column`
   includes to conditionally generate links.

3. **Enhancing link post-processing** via the `jekyll-spaceship` plugin to handle
   links with the `force-internal-link` class. This class is conditionally applied
   based on the `is_primary_site` setting. The adjustment is necessary to counteract
   the `jekyll-target-blank` plugin, which enforces opening external links in a new
   window by default.
  • Loading branch information
jcfr committed Jan 8, 2025
1 parent 613d146 commit a65df2d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
11 changes: 11 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ slicer_download_url: "https://download.slicer.org"
slicer_download_stats_url: "https://download.slicer.org/download-stats"
slicer_training_url: "https://www.slicer.org/wiki/Documentation/Nightly/Training"

# Indicates if the configuration is for the primary site (https://slicer.org).
# Set to "true" for slicer.org and "false" for auxiliary sites like the download site.
is_primary_site: true

# Cause a build to fail if there is a YAML syntax error in a page's front matter.
# See https://jekyllrb.com/docs/configuration/options/#build-command-options
strict_front_matter: true
Expand Down Expand Up @@ -61,6 +65,13 @@ plugins:
jekyll-spaceship:
processors:
- element-processor
element-processor:
css:
- 'a.force-internal-link':
props:
class: ['^(.*) force\-internal\-link$', '\0'] # force-internal-link
target: '' # Replace `target` value to ``
rel: '' # Replace `rel` value to ``

# Exclude from processing.
# The following items will not be processed, by default.
Expand Down
6 changes: 6 additions & 0 deletions _config_download.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

url: "https://download.slicer.org"

# Indicates if the configuration is for the primary site (https://slicer.org).
# Set to "true" for slicer.org and "false" for auxiliary sites like the download site.
is_primary_site: false

# Set the jinja2 template intended to be used in https://github.com/Slicer/slicer_download
slicer_download_stats_url: "{{download_stats_url}}"

Expand Down
9 changes: 8 additions & 1 deletion _includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
<div class="container">
<div class="navbar-brand">
<img src="{{ site.logo_image | absolute_url }}" width="35">
<a href="{{ '/' | absolute_url }}" class="navbar-item">
{% if site.is_primary_site -%}
{%- assign primary_site_url = '/' | absolute_url -%}
{%- assign force_internal_link_class = '' -%}
{%- else -%}
{%- assign primary_site_url = "https://slicer.org/" -%}
{%- assign force_internal_link_class = 'force-internal-link' -%}
{%- endif -%}
<a href="{{ primary_site_url }}" class="navbar-item {{ force_internal_link_class }}">
{{ site.title }}
</a>
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navMenu">
Expand Down
12 changes: 11 additions & 1 deletion _includes/navbar-column.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
{% for item in items %}

{%- assign item_link = item.link | liquify -%}

{%- assign item_link_firstchar = item_link | slice: 0, 1 -%}
{%- assign force_internal_link_class = '' -%}
{% unless site.is_primary_site %}
{% if item_link_firstchar == "/" %}
{%- assign item_link = "https://slicer.org" | append: item_link -%}
{%- assign force_internal_link_class = 'force-internal-link' -%}
{% endif %}
{% endunless %}

{%- assign item_link_prefix = item_link | slice: 0, 2 -%}
{% if item_link_prefix != "{{" %}
<a href="{{ item_link | absolute_url }}" class="navbar-item {% if item_link == page.url %}is-active{% endif %}">
<a href="{{ item_link | absolute_url }}" class="navbar-item {{ force_internal_link_class }} {% if item_link == page.url %}is-active{% endif %}">
{% else %}
<a href="{{ item_link }}" class="navbar-item" class="navbar-item {% if item_link == page.url %}is-active{% endif %}">
{% endif %}
Expand Down
12 changes: 11 additions & 1 deletion _includes/sitemap-column.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ <h4>{{ title }}</h4>
{% for item in items %}
<div>
{%- assign item_link = item.link | liquify -%}

{%- assign item_link_firstchar = item_link | slice: 0, 1 -%}
{%- assign force_internal_link_class = '' -%}
{% unless site.is_primary_site %}
{% if item_link_firstchar == "/" %}
{%- assign item_link = "https://slicer.org" | append: item_link -%}
{%- assign force_internal_link_class = 'force-internal-link' -%}
{% endif %}
{% endunless %}

{%- assign item_link_prefix = item_link | slice: 0, 2 -%}
{% if item_link_prefix != "{{" %}
<a href="{{ item_link | absolute_url }}" class="sitemap-item">
<a href="{{ item_link | absolute_url }}" class="sitemap-item {{ force_internal_link_class }}">
{% else %}
<a href="{{ item_link }}" class="sitemap-item">
{% endif %}
Expand Down

0 comments on commit a65df2d

Please sign in to comment.