jekyll-netlify-headers

jekyll-netlify-headers

A Ruby gem for generating a Netlify headers configuration from a Jekyll configuration.

jekyll-netlify-headers

A Ruby gem for generating a Netlify headers configuration from a Jekyll configuration.

Netlify's HTTP headers configuration is quite powerful. Netlify provides two options for configuring your Netlify-deployed website's rules: either in a netlify.toml file or in a _headers file.

Both file formats are perfectly serviceable, but if you're anything like me, you prefer fewer configuration files cluttering up your project. jekyll-netlify-headers allows you to configure your Netlify-deployed website's HTTP headers configuration using your project's existing Jekyll configuration file.

Getting Started

Before installing and using jekyll-netlify-headers, you'll want to familiarize yourself with Jekyll (a fabulous static site generator written in Ruby) and Netlify (a fabulous website hosting service). In particular, you'll want to read up on Netlify's Headers and Basic Authentication documentation.

Installation

If you're using Bundler, add jekyll-netlify-headers to your project's Gemfile:

source 'https://rubygems.org'

group :jekyll_plugins do
  gem 'jekyll-netlify-headers'
end

…and hop over to your command prompt and run…

$ bundle install

Usage

With jekyll-netlify-headers added to your project's Gemfile and installed, add the following to your Jekyll configuration file (typically _config.yml):

netlify:
  headers:
    - paths:
        - /templates/index.html
      headers:
        - "X-Frame-Options: DENY"
        - "X-XSS-Protection: 1; mode=block"
    - paths:
        - /templates/index2.html
        - /templates/index3.html
      headers:
        - "X-Frame-Options: SAMEORIGIN"

Note: Netlify supports a variety of HTTP header configuration options, so comb through their Headers and Basic Authentication documentation for more on the syntax. You may also want to test your HTTP header configuration at Netlify's Playground.

With this configuration added to _config.yml (or to your custom Jekyll configuration file), Jekyll will generate a properly-formatted _headers file in the destination directory when building your project.

The example above will yield a _headers file that looks like:

/templates/index.html
  X-Frame-Options: DENY
  X-XSS-Protection: 1; mode=block
/templates/index2.html
  X-Frame-Options: SAMEORIGIN
/templates/index3.html
  X-Frame-Options: SAMEORIGIN

Improving jekyll-netlify-headers

Want to help make jekyll-netlify-headers better? Hell yeah! I like your enthusiasm. For more on how you can help, check out CONTRIBUTING.md.

Donations

If diving into Ruby isn't your thing, but you'd still like to support jekyll-netlify-headers, consider making a donation! Any amount—large or small—is greatly appreciated. As a token of my gratitude, I'll add your name to the Acknowledgments below.

Acknowledgments

jekyll-netlify-headers wouldn't exist without the hard work of all the folks involved in designing, building, and maintaining Jekyll and Netlify. High fives, y'all. 🙌🏻

jekyll-netlify-headers is written and maintained by Jason Garber.

License

jekyll-netlify-headers is freely available under the MIT License. Use it, learn from it, fork it, improve it, change it, tailor it to your needs.