From 06af6d1887e5707509d5b9d9ec050f710f3fc161 Mon Sep 17 00:00:00 2001 From: samuel-denton Date: Mon, 13 Apr 2026 16:36:04 +0100 Subject: [PATCH 1/6] Added some Javascript to the theme layout which Adds target=_blank to external links so they open in a new tab. --- src/_templates/layout.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/_templates/layout.html b/src/_templates/layout.html index 7170ae5a7b9..6de9c74a35c 100644 --- a/src/_templates/layout.html +++ b/src/_templates/layout.html @@ -1 +1,14 @@ + {% extends "!layout.html" %} From 6cbb422cebe7f91c5a7c97c0f61c91ea55ff6395 Mon Sep 17 00:00:00 2001 From: samuel-denton Date: Tue, 14 Apr 2026 13:10:11 +0100 Subject: [PATCH 2/6] Moved JS from theme layout.html to static files. Added some CSS to show an icon next to external links. --- src/_static/css/custom.css | 7 +++++++ src/_static/js/extern_links_new_tab.js | 28 ++++++++++++++++++++++++++ src/_templates/layout.html | 13 ------------ src/conf.py | 23 +++++++++++++++------ 4 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 src/_static/js/extern_links_new_tab.js diff --git a/src/_static/css/custom.css b/src/_static/css/custom.css index 0610b4714fb..f7379de5b94 100644 --- a/src/_static/css/custom.css +++ b/src/_static/css/custom.css @@ -19,3 +19,10 @@ .logo { height: 7em !important; } + +/* Add an icon to external links */ +a.external::after { + content: "🔗 ↗ ⧉"; + margin-left: 0.3em; + color: black; +} diff --git a/src/_static/js/extern_links_new_tab.js b/src/_static/js/extern_links_new_tab.js new file mode 100644 index 00000000000..b6f25123509 --- /dev/null +++ b/src/_static/js/extern_links_new_tab.js @@ -0,0 +1,28 @@ +/* ---------------------------------------------------------------------------- + * Copyright (C) NIWA & British Crown (Met Office) & Contributors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * ------------------------------------------------------------------------- */ + +/* + Adds target=_blank to external links so they open in a new tab: + - noopener: prevents the new page accessing window.opener (tabnabbing protection) + - noreferrer: removes referrer info and adds extra safety +*/ +document.addEventListener("DOMContentLoaded", function () { + document.querySelectorAll('a.external').forEach(link => { + link.setAttribute('target', '_blank'); + link.setAttribute('rel', 'noopener noreferrer'); + }); +}); diff --git a/src/_templates/layout.html b/src/_templates/layout.html index 6de9c74a35c..7170ae5a7b9 100644 --- a/src/_templates/layout.html +++ b/src/_templates/layout.html @@ -1,14 +1 @@ - {% extends "!layout.html" %} diff --git a/src/conf.py b/src/conf.py index b44193c4e7b..95dda622714 100644 --- a/src/conf.py +++ b/src/conf.py @@ -239,18 +239,29 @@ def generate_task_icon_modifier_rst(): 'sidebar_version_name': None, # override name in version picker } -html_static_path = ['_static'] - -# These paths are either relative to html_static_path -# or fully qualified paths (eg. https://...) -html_css_files = ['css/custom.css'] - # Disable timestamp otherwise inserted at bottom of every page. html_last_updated_fmt = '' # Output file base name for HTML help builder. htmlhelp_basename = 'cylcdoc' +# -- Static file locations ----------------------------------------------- +html_static_path = ['_static'] + +# These paths are either relative to html_static_path +# or fully qualified paths (eg. https://...) +# NOTE: these are added to the end of the default/theme static files, so +# will override them if there are any conflicts. + +# Custom CSS +html_css_files = [ + 'css/custom.css', +] + +# Custom JS +html_js_files = [ + 'js/extern_links_new_tab.js', +] # -- Options for LaTeX output --------------------------------------------- From 01c8d4f422fe1fef21bb374e1e3e59bd0db2f517 Mon Sep 17 00:00:00 2001 From: samuel-denton Date: Tue, 14 Apr 2026 15:12:33 +0100 Subject: [PATCH 3/6] Added myself to contributors list and mailmap. --- .mailmap | 1 + CONTRIBUTING.md | 1 + src/_static/css/custom.css | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.mailmap b/.mailmap index 1838628d25a..16f9e24eb8a 100644 --- a/.mailmap +++ b/.mailmap @@ -17,3 +17,4 @@ Sadie Bartholomew Sadie L. Bartholomew <30 Tomek Trzeciak Tomek Trzeciak TomekTrzeciak Thomas Coleman <15375218+ColemanTom@users.noreply.github.com> +Samuel Denton samuel-denton diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 97998115436..183d8b70fd2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,6 +58,7 @@ requests_). - Elliot Fontaine - Mark Dawson - James Frost + - Samuel Denton (All contributors are identifiable with email addresses in the git version diff --git a/src/_static/css/custom.css b/src/_static/css/custom.css index f7379de5b94..aac4641eb8b 100644 --- a/src/_static/css/custom.css +++ b/src/_static/css/custom.css @@ -22,7 +22,8 @@ /* Add an icon to external links */ a.external::after { - content: "🔗 ↗ ⧉"; + font-size: small; + font-weight: bolder; + content: "↗"; margin-left: 0.3em; - color: black; } From 8f8533c8cfe7642c45d3c8e0b436ed4483149cdd Mon Sep 17 00:00:00 2001 From: samuel-denton Date: Thu, 23 Apr 2026 15:16:06 +0100 Subject: [PATCH 4/6] Updated CSS selector to exclude image-reference classes which look odd with an icon appended. Added hover text (title) to external links saying they are external and open in a new tab. Added an aria label for screen readers to pick up. --- src/_static/css/custom.css | 10 ++++++---- src/_static/js/extern_links_new_tab.js | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/_static/css/custom.css b/src/_static/css/custom.css index aac4641eb8b..010a8fa9933 100644 --- a/src/_static/css/custom.css +++ b/src/_static/css/custom.css @@ -20,10 +20,12 @@ height: 7em !important; } -/* Add an icon to external links */ -a.external::after { - font-size: small; +/* Add an icon to external links, excluding those with the "image-reference" class */ +a.external:not(.image-reference)::after { + font-size: 0.7em; font-weight: bolder; - content: "↗"; margin-left: 0.3em; + vertical-align: super; + opacity: 0.5; + content: "↗"; } diff --git a/src/_static/js/extern_links_new_tab.js b/src/_static/js/extern_links_new_tab.js index b6f25123509..8972c92926a 100644 --- a/src/_static/js/extern_links_new_tab.js +++ b/src/_static/js/extern_links_new_tab.js @@ -24,5 +24,7 @@ document.addEventListener("DOMContentLoaded", function () { document.querySelectorAll('a.external').forEach(link => { link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); + link.setAttribute('title', 'This link will open in a new tab and take you to an external site.'); + link.setAttribute('aria-label', 'External link: opens in a new tab'); }); }); From 256a260b51bfbb9ffbb66e8d1aa6aeea56814182 Mon Sep 17 00:00:00 2001 From: samuel-denton Date: Thu, 23 Apr 2026 15:20:27 +0100 Subject: [PATCH 5/6] added to comment --- src/_static/js/extern_links_new_tab.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/_static/js/extern_links_new_tab.js b/src/_static/js/extern_links_new_tab.js index 8972c92926a..9d6a186a959 100644 --- a/src/_static/js/extern_links_new_tab.js +++ b/src/_static/js/extern_links_new_tab.js @@ -19,6 +19,7 @@ Adds target=_blank to external links so they open in a new tab: - noopener: prevents the new page accessing window.opener (tabnabbing protection) - noreferrer: removes referrer info and adds extra safety + - title and aria-label: provide context for screen readers and tooltips */ document.addEventListener("DOMContentLoaded", function () { document.querySelectorAll('a.external').forEach(link => { From 6a1ca3cc23cbf9d4ddfad93fa2e4942f6b87896e Mon Sep 17 00:00:00 2001 From: samuel-denton Date: Thu, 23 Apr 2026 15:22:30 +0100 Subject: [PATCH 6/6] Reduced title text. --- src/_static/js/extern_links_new_tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_static/js/extern_links_new_tab.js b/src/_static/js/extern_links_new_tab.js index 9d6a186a959..109f50d1695 100644 --- a/src/_static/js/extern_links_new_tab.js +++ b/src/_static/js/extern_links_new_tab.js @@ -25,7 +25,7 @@ document.addEventListener("DOMContentLoaded", function () { document.querySelectorAll('a.external').forEach(link => { link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); - link.setAttribute('title', 'This link will open in a new tab and take you to an external site.'); + link.setAttribute('title', 'Opens in a new tab.'); link.setAttribute('aria-label', 'External link: opens in a new tab'); }); });