Small fixes
b02b7706a765410f6171c3e90ac537eb0838e5e7
1 parent
9851e3d3
index.md
+1 -0
| 1 | 1 | --- |
|
| 2 | + | title: Home |
|
| 2 | 3 | layout: default |
|
| 3 | 4 | --- |
|
| 4 | 5 | <style> |
|
| 5 | 6 | {% include index.css %} |
|
| 6 | 7 | </style> |
publish
+5 -2
| 1 | 1 | #!/usr/bin/env ruby |
|
| 2 | 2 | ||
| 3 | 3 | require 'aws-sdk-s3' |
|
| 4 | 4 | require 'digest/md5' |
|
| 5 | 5 | require 'rack/mime' |
|
| 6 | + | require 'pathname' |
|
| 6 | 7 | ||
| 7 | 8 | CLIENT = Aws::S3::Client.new(region: ENV['AWS_REGION'] || 'eu-west-1') |
|
| 8 | 9 | BUCKET = File.basename(Dir.pwd) |
|
| 9 | 10 | ||
| 10 | 11 | USAGE = <<EOF |
| 17 | 18 | AWS_SECRET_ACCESS_KEY |
|
| 18 | 19 | ||
| 19 | 20 | EOF |
|
| 20 | 21 | ||
| 21 | 22 | def upload(files=["."]) |
|
| 23 | + | base = Pathname::new(files.first) |
|
| 22 | 24 | files = files.map do |f| |
|
| 23 | 25 | File.directory?(f) ? traverse(Dir.new(f)) : f |
|
| 24 | 26 | end.flatten |
|
| 25 | 27 | ||
| 26 | 28 | files.each do |f| |
|
| 27 | 29 | print "#{f}.. " |
|
| 28 | 30 | ||
| 31 | + | key = Pathname::new(f).relative_path_from(base).to_s |
|
| 29 | 32 | mime = Rack::Mime::MIME_TYPES[File.extname(f)] |
|
| 30 | 33 | cache = if /^text/.match?(mime) then 60 else 3600 end |
|
| 31 | 34 | ||
| 32 | - | obj = CLIENT.get_object({bucket: BUCKET, key: f}) rescue nil |
|
| 35 | + | obj = CLIENT.get_object({bucket: BUCKET, key: key}) rescue nil |
|
| 33 | 36 | local_md5 = md5sum(f).chomp |
|
| 34 | 37 | remote_md5 = obj.etag.tr('"', '') if obj |
|
| 35 | 38 | ||
| 36 | 39 | if local_md5.to_s != remote_md5.to_s |
|
| 37 | 40 | CLIENT.put_object( |
|
| 38 | 41 | body: File::new(f), |
|
| 39 | - | key: f, |
|
| 42 | + | key: key, |
|
| 40 | 43 | bucket: BUCKET, |
|
| 41 | 44 | content_type: mime, |
|
| 42 | 45 | cache_control: "max-age=#{cache}", |
|
| 43 | 46 | acl: "public-read" |
|
| 44 | 47 | ) |