Code Monkey home page Code Monkey logo

posthtml-link-noreferrer's Introduction

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

posthtml-link-noreferrer's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar webistomin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.