Opening external links in new tabs
While I am not a huge fan of opening external links in new tabs, my friend Rohit suggested adding this feature, and it does make sense. And thanks to Sardine for making a simple tool for 11ty (which my blog is built using).
I used Sardine's @sardine/eleventy-plugin-external-links package which adds target="_blank"
as well as rel="noreferrer"
to all the external links.
To install, I ran the below command:
npm install --save-dev @sardine/eleventy-plugin-external-links
And then I had to add this in the 11ty config file:
const safeLinks = require('@sardine/eleventy-plugin-external-links');
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(safeLinks);
};
I think, it checks when links are not relative and then does the magic because I added an internal link using the full URL and it was opening that in the new tab. Also, I wish I could customize it a bit and also add rel="noopener"
to all external links to make it even safer. But that's not a big issue and I'm good so far.
Comment via email