Skip to content

Detect external links by host instead of url prefix#4

Open
julioalucero wants to merge 1 commit into
mainfrom
FR-740-fix-nofollow-internal-links
Open

Detect external links by host instead of url prefix#4
julioalucero wants to merge 1 commit into
mainfrom
FR-740-fix-nofollow-internal-links

Conversation

@julioalucero

Copy link
Copy Markdown
Member

Link to Jira

FR-740: Fix nofollow on internal links

PR description

Internal links (/blog/... and absolute links to our own domain) were getting nofollow, target="_blank" and the external-link icon because the old check treated anything starting with http or / as external.

What we did here:

  • Compare the link's host against the site url from _config.yml, only flag links to a different host as external.
  • Ignore the www. prefix and host casing when comparing.
  • Handle protocol-relative links (//host/...) as external too.

QA steps

  1. Try a relative link, for example /blog/something, should be internal.
  2. Add a link to your own domain (https://yoursite.com/x), should be internal.
  3. Add a link to an external site, should be external
  4. Add data-no-external="true" to an external link, should be external

@julioalucero julioalucero self-assigned this Jun 30, 2026
@julioalucero julioalucero force-pushed the FR-740-fix-nofollow-internal-links branch from 1460bad to a380c1b Compare June 30, 2026 16:02
@julioalucero julioalucero force-pushed the FR-740-fix-nofollow-internal-links branch from a380c1b to 7486849 Compare June 30, 2026 16:17
next if a['href'].nil? || a['href'].empty? || a['href'].start_with?('#') || a['data-no-external'] == 'true'

if a['href'].start_with?('http') || a['href'].start_with?('/')
if external_link?(a['href'], site_host)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want to open internal links in new tabs but without the nofollow.

Like.. you are reading an article, you click an internal link and it opens a new tab, so you are not taken away from the place you were reading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants