class Jekyll::ToS3::Deploy
Constants
- EXTENSIONS
Attributes
bucket[R]
root_path[R]
Public Class Methods
new(region:, access_key_id:, secret_access_key:, bucket:)
click to toggle source
# File lib/jekyll-to-s3.rb, line 19 def initialize(region:, access_key_id:, secret_access_key:, bucket:) credentials = Aws::Credentials.new( access_key_id, secret_access_key ) Aws.config.update( region: region, credentials: credentials ) @bucket = Aws::S3::Resource.new.bucket(bucket) @root_path = "_site" end
Public Instance Methods
deploy()
click to toggle source
# File lib/jekyll-to-s3.rb, line 36 def deploy upload_directory(root_path) cleanup_bucket end
Private Instance Methods
cleanup_bucket()
click to toggle source
# File lib/jekyll-to-s3.rb, line 67 def cleanup_bucket bucket.objects.each do |object| unless File.exists?("#{root_path}/#{object.key}") puts "Removing #{object.key}" object.delete end end end
upload_directory(path)
click to toggle source
# File lib/jekyll-to-s3.rb, line 43 def upload_directory(path) Dir["#{path}/*"].each do |file| if File.directory?(file) upload_directory(file) elsif EXTENSIONS.keys.include?(File.extname(file).downcase) key = file.split("#{root_path}/").last puts "Uploading #{key}" upload_file(Pathname.new(file), key) end end end
upload_file(path, key)
click to toggle source
# File lib/jekyll-to-s3.rb, line 55 def upload_file(path, key) object = bucket.object(key) File.open(path, 'rb') do |file| object.put( body: file, acl: 'public-read', content_type: EXTENSIONS[File.extname(path)] ) end end