[Hexo] Use hexo-filter-nofollow plugin to add nofollow attribute to all external links automatically in Hexo

hexo-filter-nofollow

Hexo is a fast, simple & powerful blog framework. It use plugins to provide features powerful APIs for limitless extensibility. Various plugins are available to support most template engines (EJS, Pug, Nunjucks, and many others). Easily integrate with existing NPM packages (Babel, PostCSS, Less/Sass, etc).

hexo-filter-nofollow plugin add nofollow attribute to all external links automatically.

hexo-filter-nofollow add `rel=“noopener external nofollow noreferrer” to all external links for security, privacy and SEO. Read more.

Installation

Use npm to install hexo-filter-nofollow package.

1
2
3
$ npm install hexo-filter-nofollow --save

$ hexo clean

Configuration

It will generate sitemap.xml in the public folder by default after hexo-filter-nofollow installation.

You can configure this plugin in ./_config.yml.

1
2
3
4
5
6
nofollow:
enable: true
field: site
exclude:
- 'exclude1.com'
- 'exclude2.com'

The follow is the options:

  • enable - Enable the plugin. Default value is true.

  • field - The scope you want the plugin to proceed, can be ‘site’ or ‘post’. Default value is site.

    • ‘post’ - Only add nofollow attribute to external links in your post content

    • ‘site’ - Add nofollow attribute to external links of whole sites

  • exclude - Exclude hostname. Specify subdomain when applicable, including www. ‘exclude1.com’ does not apply to www.exclude1.com nor en.exclude1.com.

Finally, you can visit your site in the browser, and check whether the site works correctly after Hexo restarted or regenerated.

References

[1] hexojs/hexo-filter-nofollow: Add nofollow attribute to all external links automatically. - https://github.com/hexojs/hexo-filter-nofollow/

[2] Link types - HTML: HyperText Markup Language | MDN - https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types

[3] Qualify Outbound Links for SEO | Google Search Central - https://developers.google.com/search/docs/advanced/guidelines/qualify-outbound-links

[4] Hexo - https://hexo.io/