Notoriously Psychedelic Modules
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

posthtml-link-noreferrer

1.0.7 • Public • Published

posthtml-link-noreferrer

NPM npm Deps DevDeps Build

This plugin add rel="noopener" and rel="noreferrer" to all links that contain the attribute target="_blank".

Read more about problem in google blog.

⭐️ Star us on GitHub — it helps!

Before:

<a href="/" target="_blank">External link</a>
<a href="/" target="_blank" rel="nofollow">External link</a>
<a href="/" target="_self">Home</a>

After:

<a href="/" target="_blank" rel="noopener noreferrer">External link</a>
<a href="/" target="_blank" rel="nofollow">External link</a>
<a href="/" target="_self">Home</a>

Demo

DEMO

Install

npm i posthtml-link-noreferrer --save-dev

Usage

Gulp

npm i gulp-posthtml posthtml-link-noreferrer --save-dev
const gulp = require('gulp');
const postHTML = require('gulp-posthtml');
const postHTMLNoRef = require('posthtml-link-noreferrer');
 
const config = () => ({
  plugins: [
    postHTMLNoRef({
      attr: ['noopener', 'noreferrer']
    }),
  ],
});
 
gulp.task('posthtml', () => gulp.src('./build/*.html')
  .pipe(postHTML(config))
  .pipe(gulp.dest('./build')));

Webpack

npm i html-loader posthtml-loader posthtml-link-noreferrer  --save-dev
module: {
  rules: [
    {
      test: /\.html$/,
      use: [
        'html-loader',
        {
          loader: 'posthtml-loader',
          options: {
            plugins: [
              require('posthtml-link-noreferrer')({
                attr: ['noopener', 'noreferrer']
              })
            ]
          }
        }
      ]
    }
  ]
}

Options

Option Type description Possible subsets Default value
attr array Describes rel attributes. 'noopener', 'noreferrer', 'nofollow' 'noopener', 'noreferrer'

Contributing

See PostHTML Guidelines and contribution guide.

License MIT

Install

npm i posthtml-link-noreferrer

DownloadsWeekly Downloads

147

Version

1.0.7

License

MIT

Unpacked Size

22.5 kB

Total Files

26

Last publish

Collaborators

  • avatar