npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aloskutov/eleventy-plugin-external-links

v2.1.1

Published

Eleventy external links plugin

Downloads

606

Readme

eleventy-plugin-external-links

NPM version npms.io (quality) npms.io (quality) codecov GitHub DeepScan grade

DeepSource DeepSource

Transform external links from <a href='http://external-link'> to <a href='http://external-link' rel='noreferrer nofollow noopener external' target='_blank'>.

Usage

Install via npm

npm install @aloskutov/eleventy-plugin-external-links

Load plugin in .eleventy.js

const externalLinks = require("@aloskutov/eleventy-plugin-external-links");

module.exports = (eleventyConfig) => {
    eleventyConfig.addPlugin(externalLinks, {'url': 'https://your-domain'});
};

Options

| 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 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. |

Default options

{
  url: '',
  selector: 'a',
  rel: ['noreferrer', 'nofollow', 'noopener', 'external'],
  target: '_blank',
  overwrite: true,
  excludedProtocols: [],
  doctype: '<!doctype html>',
  addDoctype: false,
  ext: ['.html'],
  excludedDomains: [],
  enableTarget: true,
}

Notes

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.

Examples

With default values, except url

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-id
  • https://www.example.com/some-link
  • https://www.example.com:443/some-link
  • http://www.example.com/some-link
  • http://www.example.com:8080/some-link
  • ftp://www.example.com/some-link
  • //www.example.com/some-link
  • www.example.com/some-link
  • www.example.com

External links

  • http://www.google.com
  • http://www.google.com:80
  • https://www.google.com
  • https://www.google.com:443
  • ftp://www.google.com
  • protocol://www.google.com
  • //www.google.com
  • www.google.com

The following links are not processed

  • mailto:[email protected]
  • tel:1234567890
  • file:/some/file
  • javascript:alert(0)
  • telnet://192.0.2.16:80/
  • urn:oid:1.2.840.113549.1.1.1
  • sip:[email protected]
  • news:comp.infosystems.www.servers.unix

TODO

  • [x] add excludedDomains. List of addresses that will be excluded from processing. These links will not be considered external and will remain unchanged.
  • [x] add addDoctype. Optional doctype <!doctype html>
  • [x] add doctype. Doctype string. Default: <!doctype html>
  • [x] add ext. List of processed files, not only .html files. Default: .html
  • [x] support IDN (Internationalized Domain Names)
  • [x] add support for partial html code
  • [ ] further reduce the impact on the html source code

Changes

2.1.0

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.

v.2.0

  • Changed html parsing library from JSDOM to node-html-parser.
  • Increased speed of html code processing.
  • The addDoctype option is now, set to false.
  • 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>).