Transform external links from <a href='http://external-link'> to <a href='http://external-link' rel='noreferrer nofollow noopener external' target='_blank'>.
npm install @aloskutov/eleventy-plugin-external-linksconst externalLinks = require("@aloskutov/eleventy-plugin-external-links");
module.exports = (eleventyConfig) => {
eleventyConfig.addPlugin(externalLinks, {'url': 'https://your-domain'});
};| Option | Type | Default | Description |
|---|---|---|---|
| url | string | '' | If not set, all non-relative links are considered external. |
| rel | array or string | ['noreferrer', 'nofollow', 'noopener', 'external'] | link rel attribute |
| target | string | _blank | link target attribute |
| overwrite | boolean | true | Overwrite attribute values or not. If the value is false, then the existing attribute is not overwritten. |
| excludedProtocols | array | [] | Exclude links with matching protocols from processing. The protocol must be specified without a colon. Ex. ['ftp'] |
| doctype | string | '<!doctype html>' | Doctype value |
| addDoctype | boolean | false | Add doctype to result or not |
| ext | array | ['.html'] | Extensions |
| excludedDomains | array or string | [] | For cross-linked domains and subdomains. Array or string of values separated by comma, semicolon, tab or space symbols. |
| enableTarget | boolean | true | Option to enable/disable the 'target' attribute. Default value is true, i.e. target is enabled. |
{
url: '',
selector: 'a',
rel: ['noreferrer', 'nofollow', 'noopener', 'external'],
target: '_blank',
overwrite: true,
excludedProtocols: [],
doctype: '<!doctype html>',
addDoctype: false,
ext: ['.html'],
excludedDomains: [],
enableTarget: true,
}The site address can be specified without a protocol, only the fully qualified domain name. For example, www.example.com or https://www.example.com or //www.example.com
Addresses with protocols other than http, https, ftp and ftps are excluded from processing and remain unchanged.
const externalLinks = require('@aloskutov/eleventy-plugin-external-links');
module.exports = (eleventyConfig, options = {}) => {
// some code
eleventyConfig.addPlugin(externalLinks, {url: "www.example.com"});
//some code
};Local links:
/some-link/?link-with-query-string#link-with-idhttps://www.example.com/some-linkhttps://www.example.com:443/some-linkhttp://www.example.com/some-linkhttp://www.example.com:8080/some-linkftp://www.example.com/some-link//www.example.com/some-linkwww.example.com/some-linkwww.example.com
External links
http://www.google.comhttp://www.google.com:80https://www.google.comhttps://www.google.com:443ftp://www.google.comprotocol://www.google.com//www.google.comwww.google.com
The following links are not processed
mailto:some@address.comtel:1234567890file:/some/filejavascript:alert(0)telnet://192.0.2.16:80/urn:oid:1.2.840.113549.1.1.1sip:911@pbx.mycompany.comnews:comp.infosystems.www.servers.unix
- add
excludedDomains. List of addresses that will be excluded from processing. These links will not be considered external and will remain unchanged. - add
addDoctype. Optional doctype<!doctype html> - add
doctype. Doctype string. Default:<!doctype html> - add
ext. List of processed files, not only.htmlfiles. Default:.html - support IDN (Internationalized Domain Names)
- add support for partial html code
- further reduce the impact on the html source code
Added enableTarget option with default value true. If for some reason you need to disable the target attribute, set the enableTarget option to false.
This option does not break backwards compatibility.
- Changed html parsing library from
JSDOMtonode-html-parser. - Increased speed of html code processing.
- The
addDoctypeoption is now, set tofalse. - The impact of the parsing library on the html code has been reduced. JSDOM forced wrapping in
<html>if it was missing. It was not possible to work with code fragments (not wrapped in<html>).