Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rel="noopener" or rel="noreferrer" to any external links #216

Open
LoneRifle opened this issue Jan 7, 2021 · 1 comment
Open

Add rel="noopener" or rel="noreferrer" to any external links #216

LoneRifle opened this issue Jan 7, 2021 · 1 comment

Comments

@LoneRifle
Copy link
Contributor

Fulfill Lighthouse audit items by detecting external links and adding the appropriate attribute

@rc-davis
Copy link

rc-davis commented Mar 15, 2022

We can use the jekyll-target-blank plugin to automatically add the attributes target="_blank" and rel="noopener noreferrer" to all external links in pages, posts and custom collections.

Doing this will involve three steps:

  1. Update each site to use the jekyll-target-blank gem.
  2. Update the _config.yml for each site, adding jekyll-target-blank to the plugins section.
  3. Rebuild every site.

This will be quite painful unless we can automate these steps. We can automate step 2 by updating the update-repo-files script to modify _config.yml files. Automating steps 1 and 3 will be easier for CMS sites than for older sites. Consider the following:

  • We can make CMS sites use the jekyll-target-blank gem simply by updating the public isomer-jekyll gem to include it. For sites that do not use isomer-jekyll, we'll have to update their Gemfiles manually or write a script similar to update-repo-files to do it.
  • We can use the rebuild-sites script to rebuild all sites, but this script needs metadata that we must currently collect manually (domain name, netlify site id, and keycdn zone id). We could automate similar changes more easily in the future if we stored this metadata in a database that rebuild-sites can read. This makes sense for CMS sites, but not for older sites.

Since this change is not urgent, it seems best to automate it after all older sites are either moved out of the Isomer org or updated to use the isomer CMS. Once we can assume that all sites are on the Isomer CMS, we can automate this change and then reuse our approach when making similar updates in the future.

Finally, note that after we start using the jekyll-target-blank plugin we may still need to fix a few external links here and there. For example, the jekyll-target-blank plugin doesn't appear to affect maps_links in contact-us.md. The contact_us layout processes external links with the external_url function, which adds target="_blank" rel="noreferrer" to external links. (This is probably good enough, but we could add noopener for consistency). There may more external links that we haven't noticed yet, so we should do a thorough check.

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

No branches or pull requests

2 participants