Repository is archived
No commit activity in last 3 years
No release in over 3 years
Set Content-Type metadata for S3 objects after syncing.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0

Runtime

 Project Readme

Middleman::S3Metadata

Code Climate

This gem automates updating metadata of specific AWS S3 object.

Use case:

  • Set suitable Content-Type for RSS file
  • Remove 'Cache-Control' and 'Expires' header to disable strong caching

Compatibility

  • middleman-s3_metadata 0.2.x is for Middleman 4.x
  • middleman-s3_metadata 0.1.x is for Middleman 3.x

Installation

Add this line to your application's Gemfile:

gem 'middleman-s3_metadata'

And then execute:

$ bundle

Or install it yourself as:

$ gem install middleman-s3_metadata

Usage

You need to add the following code to your config.rb file:

activate :s3_metadata do |config|
  config.bucket                = 'my.bucket.com' # The name of the S3 bucket you are targetting. This is globally unique.
  config.region                = 'us-west-1'     # The AWS region for your bucket.
  config.aws_access_key_id     = 'AWS KEY ID'
  config.aws_secret_access_key = 'AWS SECRET KEY'
  config.after_build           = false # We chain after the build step by default. This may not be your desired behavior...
end

The s3_metadata method set a metadata for S3 object:

# Set suitable Content-Type
s3_metadata('feeds/feed.rss', 'Content-Type', 'rss/xml')
s3_metadata('archives.tar.gz', 'Content-Type', 'application/x-gzip')

# Disable caching
s3_metadata('index.html', 'Cache-Control', nil)
s3_metadata('index.html', 'Expires', nil)

First argument is key for S3 object, second and third arguments is key and value for metadata.

A Debt of Gratitude

I used middleman-sync and middleman-s3_redirect as a template for building a Middleman extension. My gratitude goes to @karlfreeman and @fredjean.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request