zine 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd799d0d16019f2d33ecaf9b60bb5a9c13d8d3b8b82b03f4ff7d8781d5fbcfde
4
- data.tar.gz: bc32bc64300c4b8327c6426335533970656ab9a33e06fe5e3976ac51c8b14bc6
3
+ metadata.gz: 83a6d732e0f716bf2df642356304e6e80622736f778ff6367e3bf742a3d55f04
4
+ data.tar.gz: 75c284e7e74f8594372c2be764590de57a2a1072b70e989136c09130948478ea
5
5
  SHA512:
6
- metadata.gz: 91d373f480d5282ddaf6a08d08bb69528cf62e7d5cb7532aa4cfb98e5f40cc5ef7f4a9723c41ce2d9961f7650524ac2d4f69cc2da84b3237ebf5c9e11b43fc91
7
- data.tar.gz: 1325ebca737a5f0bc73641e745bf3466d78a5f2f5f14914c0e8c41953c441ae47c4cf55a7e4527c30079512c45808d6ad63204486c1b52c3ccfc9b14a3e33063
6
+ metadata.gz: 95a3b894f4d3cc1c03bce1509990de4185f5f7c503d694c440dd3c730bc45e49b9e01a65f60a94d5976e5cef4da77c802fdd6bc7133c3028618d8f1dc3485376
7
+ data.tar.gz: 5aaa407679487a1e807722e79d02f523ac0b75fa73b595e8fb2a2ece08157b1d3d6bbcca678256b40bc7327662886b48a419d7e2b377d750043a1d7a3e1bccda
@@ -126,11 +126,11 @@
126
126
 
127
127
  - fixed a bug where String#split would break apart markdown files on tables as well as at the metadata/markdown boundary
128
128
 
129
- # 0.12.0 - never pushed, used up until 25 April 2019
129
+ # 0.12.0 - never pushed, used up until April 25, 2019
130
130
 
131
131
  - added (then removed) Mastodon from the list of contacts, changed the styling a few times, neglected to publish
132
132
 
133
- # 0.13.0 - lucky 13 -
133
+ # 0.13.0 - lucky 13 - May 26, 2019
134
134
 
135
135
  - added some of the style changes that survived from v12, eg moved social media to the footer
136
136
  - added a (permissive as they come) robots.txt file
@@ -140,11 +140,15 @@
140
140
  - minor readme updates
141
141
  - placeholder site, mostly in case there's ever an app: https://zine.dev
142
142
 
143
+ # 0.14.0 - May 27, 2019
144
+ - added an AWS S3 uploader
145
+ - added AWS CloudFront invalidation
146
+ - added zine.dev to the footer template
147
+ - bug fix - catch carriage returns as default yes answers to the upload? question
148
+
143
149
  TO DO
144
150
  - add canonical links to page headers, means the build order needs to change...
145
151
  - generate sitemap.xml
146
- - add an AWS S3 uploader
147
- - add AWS CloudFront invalidation
148
152
  - fix the SFTP error from 0.7/0.8, also likely applies to S3
149
153
  - make sure the server's killed on errors (eg if no credentials) so can run it again later without a port conflict
150
154
  - tests, lots of tests
@@ -153,5 +157,5 @@ MAY DO
153
157
  - concurrent-ruby gem
154
158
  - migration scripts from eg Jekyll?
155
159
  - Apple News
156
- - much refactoring
157
- - an app
160
+ - much refactoring, frozen_string_literal, split monster classes, etc
161
+ - an app... maybe
data/README.md CHANGED
@@ -6,14 +6,14 @@ Yet another blog aware static site generator.
6
6
 
7
7
  ## Why yet another static blog engine?
8
8
 
9
- Despite the [proliferation in these things][engine_list] (!) I still find it more comfortable to use my own tools.
9
+ Despite the [proliferation in these things][engine_list] (!) I still find it more comfortable to use my own tools, changing them to suit my changing needs, for example here as I've moved between GitHub, EC2 & S3 hosts.
10
10
 
11
11
  Distinguishing features include:
12
12
 
13
13
  - ERB templates
14
14
  - Sass stylesheets
15
15
  - fast incremental builds
16
- - GitHub & SFTP file uploads
16
+ - a choice of AWS S3, GitHub & SFTP file uploads
17
17
 
18
18
  Presented here in the hope it's of use to someone else too.
19
19
 
@@ -3,7 +3,8 @@ module Zine
3
3
  class Query
4
4
  def call(question)
5
5
  puts question
6
- $stdin.gets.chomp
6
+ result = $stdin.gets.chomp
7
+ result == '' ? 'Y' : result
7
8
  end
8
9
  end
9
- end
10
+ end
@@ -17,7 +17,7 @@
17
17
  <div class="column">
18
18
  <h3>The fine print</h3>
19
19
  <ul>
20
- <li>Built with <a href="https://github.com/mikekreuzer/zine">Zine</a></li>
20
+ <li>Built with <a href="https://zine.dev">Zine</a></li>
21
21
  <li>&copy; 2019<span> <%= page[:site_author] %></span></li>
22
22
  </ul>
23
23
  </div>
@@ -33,8 +33,9 @@ templates:
33
33
  tag: tag
34
34
  tag_index: tag_index
35
35
  upload:
36
+ cloudfront_distrib: ID or ''
36
37
  credentials: /local/absolute/path/to/yaml/file/with/username/password/or/access_token
37
- host: 127.0.0.1
38
- method: none|github|sftp
38
+ host: eg 127.0.0.1, or for AWS region:bucket_name
39
+ method: none|aws|github|sftp
39
40
  path_or_repo: /remote/absolute/path/to/html|fullname/repo
40
41
  verbose: true
@@ -1,11 +1,12 @@
1
1
  require 'rainbow'
2
2
  require 'set'
3
3
  require 'zine'
4
+ require 'zine/uploader_aws'
4
5
  require 'zine/uploader_github'
5
6
  require 'zine/uploader_sftp'
6
7
 
7
8
  module Zine
8
- # Deploy changes to a remote host, via SFTP or using the GitHub Rest API
9
+ # Deploy changes to a remote host, via SFTP or using the AWS or GitHub API
9
10
  class Upload
10
11
  def initialize(build_dir, options, delete_file_array, upload_file_array)
11
12
  if options['method'] == 'none'
@@ -45,6 +46,15 @@ module Zine
45
46
  exit
46
47
  end
47
48
 
49
+ def aws_upload
50
+ uploader = Zine::UploaderAWS.new(@build_dir,
51
+ @options,
52
+ @credentials,
53
+ @delete_file_array,
54
+ @upload_file_array)
55
+ uploader.upload
56
+ end
57
+
48
58
  def github_upload
49
59
  uploader = Zine::UploaderGitHub.new(@build_dir,
50
60
  @options,
@@ -64,7 +74,9 @@ module Zine
64
74
  end
65
75
 
66
76
  def upload
67
- if @options['method'] == 'sftp'
77
+ if @options['method'] == 'aws'
78
+ aws_upload
79
+ elsif @options['method'] == 'sftp'
68
80
  sftp_upload
69
81
  elsif @options['method'] == 'github'
70
82
  github_upload
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aws-sdk-cloudfront'
4
+ require 'aws-sdk-s3'
5
+ require 'rack/mime'
6
+ require 'rainbow'
7
+ require 'set'
8
+
9
+ module Zine
10
+ # Deploy changes to an AWS S3 bucket and invalidate the Cloudfront cache
11
+ class UploaderAWS
12
+ def initialize(build_dir, options, credentials, delete_file_array,
13
+ upload_file_array)
14
+ return unless options['method'] == 'aws'
15
+
16
+ @build_dir = build_dir
17
+ ENV['AWS_REGION'], @bucket_name = options['host'].split(':')
18
+ @path = options['path_or_repo']
19
+ @cf_distribution_id = options['cloudfront_distrib']
20
+
21
+ @verbose = options['verbose']
22
+ store_credentials credentials
23
+ @delete_file_array = Set.new(delete_file_array).to_a
24
+ @upload_file_array = Set.new(upload_file_array).to_a
25
+
26
+ @s3 = Aws::S3::Client.new
27
+ @cf = Aws::CloudFront::Client.new
28
+ end
29
+
30
+ def upload
31
+ delete
32
+ deploy
33
+ invalidate
34
+ rescue Aws::S3::Errors::ServiceError => err
35
+ puts Rainbow("S3 error: #{err}").red
36
+ end
37
+
38
+ private
39
+
40
+ def clean_path(path)
41
+ path.to_s
42
+ .delete_prefix('/')
43
+ .delete_suffix('/')
44
+ end
45
+
46
+ def delete
47
+ @delete_file_array.each do |rel_path|
48
+ remote_path = clean_path(rel_path)
49
+ @s3.delete_object(bucket: @bucket_name, key: remote_path)
50
+ puts "Delete: #{remote_path}" if @verbose
51
+ end
52
+ end
53
+
54
+ def deploy
55
+ @upload_file_array.each do |rel_path|
56
+ deploy_one_file(File.join(@build_dir, rel_path),
57
+ clean_path(rel_path))
58
+ end
59
+ end
60
+
61
+ def deploy_one_file(local_path, remote_path)
62
+ File.open(local_path, 'rb') do |file|
63
+ content_type = Rack::Mime.mime_type(File.extname(local_path))
64
+ @s3.put_object(bucket: @bucket_name,
65
+ key: remote_path,
66
+ content_type: content_type,
67
+ body: file)
68
+ puts "Add: #{remote_path}" if @verbose
69
+ end
70
+ end
71
+
72
+ def invalidate
73
+ changes = Set.new(@upload_file_array + @delete_file_array).to_a
74
+ return unless changes.count.positive?
75
+
76
+ puts 'Invalidating cache' if @verbose
77
+ string_changes = changes.map do |path|
78
+ path.to_s
79
+ .delete_prefix('/')
80
+ .prepend('/')
81
+ end
82
+ string_changes << '/'
83
+ @cf.create_invalidation(
84
+ distribution_id: @cf_distribution_id,
85
+ invalidation_batch: { paths: { quantity: string_changes.count,
86
+ items: string_changes },
87
+ caller_reference: Time.now.to_i.to_s }
88
+ )
89
+ end
90
+
91
+ def store_credentials(creds)
92
+ ENV['AWS_ACCESS_KEY_ID'] = creds['username']
93
+ ENV['AWS_SECRET_ACCESS_KEY'] = creds['password']
94
+ end
95
+ end
96
+ end
@@ -1,4 +1,4 @@
1
1
  module Zine
2
2
  # The version
3
- VERSION = '0.13.0'.freeze
3
+ VERSION = '0.14.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Kreuzer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-25 00:00:00.000000000 Z
11
+ date: 2019-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,6 +92,34 @@ dependencies:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
94
  version: 0.16.1
95
+ - !ruby/object:Gem::Dependency
96
+ name: aws-sdk-cloudfront
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '1.18'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '1.18'
109
+ - !ruby/object:Gem::Dependency
110
+ name: aws-sdk-s3
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '1.40'
116
+ type: :runtime
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '1.40'
95
123
  - !ruby/object:Gem::Dependency
96
124
  name: htmlcompressor
97
125
  requirement: !ruby/object:Gem::Requirement
@@ -304,6 +332,7 @@ files:
304
332
  - lib/zine/tag.rb
305
333
  - lib/zine/templates.rb
306
334
  - lib/zine/upload.rb
335
+ - lib/zine/uploader_aws.rb
307
336
  - lib/zine/uploader_github.rb
308
337
  - lib/zine/uploader_sftp.rb
309
338
  - lib/zine/version.rb