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
- middleman-s3_metadata 0.2.x is for Middleman 4.x
- middleman-s3_metadata 0.1.x is for Middleman 3.x
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
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.
I used middleman-sync and middleman-s3_redirect as a template for building a Middleman extension. My gratitude goes to @karlfreeman and @fredjean.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request