From 5aa56c054fffd489070484a46c498d55ee051428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 15 Oct 2023 18:22:15 +0200 Subject: [PATCH] Mark external links using the "rel" attribute This will help search engines know these links point to external sites and it'll make it possible to style these links using the `[rel~=external]` selector. AFAIK, assistive techonologies don't use this attribute to notify people about external links, though. --- app/components/layout/footer_component.rb | 8 ++++++-- spec/components/layout/footer_component_spec.rb | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/components/layout/footer_component.rb b/app/components/layout/footer_component.rb index 58278899b..77148401a 100644 --- a/app/components/layout/footer_component.rb +++ b/app/components/layout/footer_component.rb @@ -8,11 +8,15 @@ class Layout::FooterComponent < ApplicationComponent private def open_source_link - link_to(t("layouts.footer.open_source"), t("layouts.footer.open_source_url"), rel: "nofollow") + external_link_to(t("layouts.footer.open_source"), t("layouts.footer.open_source_url")) end def repository_link - link_to(t("layouts.footer.consul"), t("layouts.footer.consul_url"), rel: "nofollow") + external_link_to(t("layouts.footer.consul"), t("layouts.footer.consul_url")) + end + + def external_link_to(text, url) + link_to(text, url, rel: "nofollow external") end def allowed_link_attributes diff --git a/spec/components/layout/footer_component_spec.rb b/spec/components/layout/footer_component_spec.rb index d44e52e01..59cb2cf73 100644 --- a/spec/components/layout/footer_component_spec.rb +++ b/spec/components/layout/footer_component_spec.rb @@ -6,7 +6,9 @@ describe Layout::FooterComponent do render_inline Layout::FooterComponent.new page.find(".info") do |info| - expect(info).to have_css "a[rel=nofollow]", count: 2 + expect(info).to have_css "a", count: 2 + expect(info).to have_css "a[rel~=nofollow]", count: 2 + expect(info).to have_css "a[rel~=external]", count: 2 expect(info).not_to have_css "a[target]" end end