Update website

7a6c36ba136e9421faa5f26b82e3297f7ab46084
Alexis Sellier committed ago 1 parent 3b74a933
index.html +4 -5
7 7
  <body>
8 8
    <header>
9 9
      <nav>
10 10
        <h1>cloudhead</h1>
11 11
        <ul>
12 -
          <li><a href="/code">code</a></li>
12 +
          <li><a href="https://github.com/cloudhead">code</a></li>
13 13
          <li><a href="https://twitter.com/cloudhead">tweets</a></li>
14 -
          <li><a href="https://mylifeofmusic.com">music</a></li>
14 +
          <li><a href="https://merveilles.town/@cloudhead">toots</a></li>
15 15
          <li><a href="https://ello.co/cloudhead">drawings</a></li>
16 -
          <li><a href="https://letterboxd.com/cloudhead/">film</a></li>
17 -
          <li><a href="https://goodreads.com/cloudhead/">books</a></li>
18 -
          <li><a href="https://github.com/cloudhead">gits</a></li>
16 +
          <li><a href="https://github.com/cloudhead/dotfiles">dotfiles</a></li>
17 +
          <li><a href="https://github.com/cloudhead/shady.vim">shady</a></li>
19 18
          <li><a href="https://rx.cloudhead.io">rx</a></li>
20 19
        </ul>
21 20
      </nav>
22 21
    </header>
23 22
    <footer>
publish +18 -10
1 1
#!/usr/bin/env ruby
2 2
3 -
require 'aws-sdk-v1'
3 +
require 'aws-sdk-s3'
4 4
require 'digest/md5'
5 5
require 'rack/mime'
6 6
7 -
SITE = AWS::S3.new(region: ENV['AWS_REGION'] || 'eu-west-1')
8 -
              .buckets[File.basename(Dir.pwd)]
7 +
CLIENT = Aws::S3::Client.new(region: ENV['AWS_REGION'] || 'eu-west-1')
8 +
BUCKET = File.basename(Dir.pwd)
9 9
10 10
USAGE = <<EOF
11 11
usage: #{$0} file...
12 12
13 13
the following environment vars will be used:
22 22
  files = files.map do |f|
23 23
    File.directory?(f) ? traverse(Dir.new(f)) : f
24 24
  end.flatten
25 25
26 26
  files.each do |f|
27 -
    obj = SITE.objects[f]
28 -
    local_md5 = md5sum(f).chomp
29 -
    remote_md5 = obj.etag.tr('"', '') if obj.exists?
30 -
31 27
    print "#{f}.. "
32 28
29 +
    mime = Rack::Mime::MIME_TYPES[File.extname(f)]
30 +
    cache = if /^text/.match?(mime) then 60 else 3600 end
31 +
32 +
    obj = CLIENT.get_object({bucket: BUCKET, key: f}) rescue nil
33 +
    local_md5 = md5sum(f).chomp
34 +
    remote_md5 = obj.etag.tr('"', '') if obj
35 +
33 36
    if local_md5.to_s != remote_md5.to_s
34 -
      obj.write(Pathname.new(f),
35 -
                :content_type => Rack::Mime::MIME_TYPES[File.extname(f)])
36 -
      obj.acl = :public_read
37 +
      CLIENT.put_object(
38 +
        body: File::new(f),
39 +
        key: f,
40 +
        bucket: BUCKET,
41 +
        content_type: mime,
42 +
        cache_control: "max-age=#{cache}",
43 +
        acl: "public-read"
44 +
      )
37 45
38 46
      puts "ok"
39 47
    else
40 48
      puts "skipping"
41 49
    end