middleman-cdn 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 3c69df7b602f0dab070c27d9c0ad63b7b91a6c0b
4
- data.tar.gz: 0bd77eba0b7256212615c526de25f04d8dc2d250
3
+ metadata.gz: 69067babbcf6c181de78867c0a26cd0419f1cd7f
4
+ data.tar.gz: 9a2adde88d7fce458d9c04d29dd48728403c708d
5
5
  SHA512:
6
- metadata.gz: 7d713c1b93db2a90b5be5472ab9be51dbc381fce5c32e3546569e383edb34b92330d7db6a945a2daab393fbb5799a15bbb381915fa93dd3a26a7b8df896d860f
7
- data.tar.gz: ad09374e358f9e36be4aa94555ca6254f4572a0616bcf3a8beffc2c0d21c532243c8a2add8bd8f132c65ae5f115350539136f778ab07c6b2380db30505f05311
6
+ metadata.gz: 1f353a06b8b40e21e040c5797c504f15afe500b5264ea476e91ba587f7ea26e2e8114aac2bfc9bea10f03c5dab5886d7630cca98ecbc6534557268154c9b01ac
7
+ data.tar.gz: 2627680904f589d2901a5732549c19105ea017dcbafcac74f986efd57f1747c3e1ab194f0d8bba957c8fa0d1c848ab695b818eb380fe64ea84e6e8aa3a8eb835
data/README.md CHANGED
@@ -1,22 +1,20 @@
1
1
  # Middleman CDN [![Build Status](https://travis-ci.org/leighmcculloch/middleman-cdn.svg)](https://travis-ci.org/leighmcculloch/middleman-cdn) [![Dependency Status](https://gemnasium.com/leighmcculloch/middleman-cdn.png)](https://gemnasium.com/leighmcculloch/middleman-cdn)
2
- A deploying tool for middleman which allows you to invalidate resources cached
3
- on the CloudFlare and Amazon CloudFront CDNs. Specifically useful if your
4
- using multiple CDNs to cache the content of your middleman website.
2
+ A [middleman](http://middlemanapp.com/) deploy tool for invalidating resources cached
3
+ on common Content Delivery Networks (CDNs).
5
4
 
6
5
  * Cache invalidation of files on:
7
6
  * CloudFlare
8
7
  * Amazon CloudFront
9
- * **Use another CDN? Open an issue and I'll do it.**
10
- * Invalidate files on multiple CDNs.
11
- * Call from the command line.
12
- * Call automatically after middleman build.
13
- * Ability to select/filter files to be invalidated by regex.
8
+ * Select files for invalidation with regex.
9
+ * Automatically invalidate after build.
10
+ * Manually trigger invalidation with single command.
14
11
 
15
12
  What's next?
16
13
 
17
14
  * Expand the test base.
18
15
  * Add support for Fastly.
19
16
  * Add support for MaxCDN.
17
+ * [Open an issue](../../issues/new) if you'd like your CDN provider added.
20
18
 
21
19
  # Usage
22
20
 
@@ -33,15 +31,20 @@ bundle install
33
31
 
34
32
  ## Configuration
35
33
 
36
- Edit `config.rb` and add the following. Specify either one CDN config or
37
- multiple.
34
+ Edit your middleman `config.rb` and add the following. Specify either one or
35
+ more CDN configurations.
38
36
  ```ruby
39
37
  activate :cdn do |cdn|
40
38
  cdn.cloudflare = {
41
- client_api_key: '...', # default ENV['CLOUDFLARE_CLIENT_API_KEY']
42
- email: 'you@example.com', # default ENV['CLOUDFLARE_EMAIL']
39
+ client_api_key: '...', # default ENV['CLOUDFLARE_CLIENT_API_KEY']
40
+ email: 'you@example.com', # default ENV['CLOUDFLARE_EMAIL']
43
41
  zone: 'example.com',
44
- base_urls: ['http://example.com', 'https://example.com']
42
+ base_urls: [
43
+ 'http://example.com',
44
+ 'http://www.example.com',
45
+ 'https://example.com',
46
+ 'https://www.example.com'
47
+ ]
45
48
  }
46
49
  cdn.cloudfront = {
47
50
  access_key_id: '...', # default ENV['AWS_ACCESS_KEY_ID']
@@ -49,12 +52,67 @@ activate :cdn do |cdn|
49
52
  distribution_id: '...'
50
53
  }
51
54
  cdn.filter = /\.html/i # default /.*/
52
- cdn.after_build = true # default is false
55
+ cdn.after_build = true # default is false
53
56
  end
54
57
  ```
55
58
 
56
- Instead of storing your CDN credentials in config.rb store them in the
57
- environment variables specified above, or execute on the commandline as:
59
+ ### Configuration: Filter
60
+
61
+ The `filter` parameter defines which files in your middleman `build` directory
62
+ will be invalidated on the CDN. It must be a regular expression (use
63
+ [rubular](http://rubular.com/) to test your regex).
64
+
65
+ Examples:
66
+
67
+ | Files | Regex |
68
+ |:------------- |:------------- |
69
+ | HTML files | `/\.html$/i` |
70
+ | All files | `/.*/` |
71
+
72
+ It's better to always invalidate only the files you need. If you're using
73
+ [middleman's asset pipeline](http://middlemanapp.com/basics/asset-pipeline/) to
74
+ generate fingerprinted CSS, JS and images, then you should never need to
75
+ invalidate them.
76
+
77
+ Note: Directories containing `index.html` files are automatically included
78
+ when their respective `index.html` is included in the filter.
79
+
80
+ ### Configuration: CloudFlare
81
+
82
+ The `cloudflare` parameter contains the information specific to your CloudFlare
83
+ account and which zone (domain) files should be invalidated for. CloudFlare
84
+ invalidation works off URLs not filenames, and you must provide a list of
85
+ base urls to ensure we invalidate every URL that your files might be accessed
86
+ from.
87
+
88
+ | Parameter | Description |
89
+ |:--------- |:----------- |
90
+ | `client_api_key` | You can find this by logging into CloudFlare, going to your account page and it will be down the bottom left. |
91
+ | `email` | The email address that you use to login to CloudFlare with. |
92
+ | `zone` | The domain name of the website we are invalidating. |
93
+ | `base_urls` | An array of base URLs that the files are accessible at. |
94
+
95
+ CloudFlare invalidations take mere seconds.
96
+
97
+ ### Configuration: CloudFront
98
+
99
+ The `cloudfront` parameter contains the information specific to your AWS CloudFront
100
+ account and which distribution files should be invalidated for.
101
+
102
+ | Parameter | Description |
103
+ |:--------- |:----------- |
104
+ | `access_key_id` | AWS Access Key ID (generate in AWS Console IAM) |
105
+ | `secret_access_key` | AWS Secret Access Key (generate in AWS Console IAM) |
106
+ | `distribution_id` | The distribution ID on the CloudFront distribution. |
107
+
108
+ CloudFront invalidations take up to 15 minutes. You can monitor the progress of
109
+ the invalidation in your AWS Console.
110
+
111
+ ### Credentials via Environment Variables
112
+
113
+ Instead of storing your CDN credentials in config.rb where they may be public
114
+ on github, store them in environment variables, or execute on the
115
+ commandline as:
58
116
 
59
117
  ```bash
60
118
  CLOUDFLARE_CLIENT_API_KEY= CLOUDFLARE_EMAIL= AWS_ACCESS_KEY= AWS_SECRET= bundle exec middleman invalidate
@@ -67,19 +125,20 @@ Set `after_build` to `true` and the cache will be invalidated after build:
67
125
  bundle exec middleman build
68
126
  ```
69
127
 
70
- Otherwise, invalidate manually using:
128
+ Invalidate manually using:
71
129
  ```bash
72
130
  bundle exec middleman invalidate
73
131
  ```
74
132
 
75
- Or, shorthand:
133
+ Or:
76
134
  ```bash
77
135
  bundle exec middleman inv
78
136
  ```
79
137
 
80
- ## In the wild
138
+ ## Example Usage
81
139
 
82
- I'm using middleman-cdn on my personal website leighmcculloch.com on github.
140
+ I'm using middleman-cdn on my personal website [leighmcculloch.com](http://leighmcculloch.com) which is on [github](https://github.com/leighmcculloch/leighmcculloch.com) if you want to checkout how I deploy. Unlike CloudFront, CloudFlare doesn't default to caching HTML. Configure a PageRule that looks like this to tell CloudFlare's edge to cache everything.
141
+ ![CloudFlare PageRule Example](README-cloudflare-pagerule-example.png)
83
142
 
84
143
  ## Thanks
85
144
 
@@ -87,4 +146,8 @@ Middleman CDN is a fork off [Middleman CloudFront](https://github.com/andrusha/m
87
146
 
88
147
  Thanks to @b4k3r for the [Cloudflare gem](https://github.com/b4k3r/cloudflare) that made invalidating CloudFlare files a breeze.
89
148
 
90
- Thanks to @cloudflare for CloudFlare.
149
+ ## Why Middleman CDN
150
+
151
+ Middleman CloudFront is a great extension for Middleman and perfect if you're using CloudFront. I use CloudFlare primarily and I wanted to create a similar extension for it specifically. However, it's becoming increasingly common for static websites to be hosted across multiple CDNs. [jsDelivr](http://jsdelivr.com/) is a well known promoter of this strategy.
152
+
153
+ In light of the new trends in how we are using CDNs, I decided it would be more worthwhile to create an extension that can grow to support all the popular CDNs.
@@ -17,13 +17,15 @@ module Middleman
17
17
  def initialize(app, options_hash = {}, &block)
18
18
  super
19
19
 
20
- app.after_build do
21
- ::Middleman::Cli::CDN.new.invalidate(options) if options.after_build
20
+ @@cdn_options = options
21
+
22
+ app.after_configuration do
23
+ app.after_build do
24
+ ::Middleman::Cli::CDN.new.invalidate(@@cdn_options) if @@cdn_options.after_build
25
+ end
22
26
  end
23
27
 
24
28
  app.send :include, Helpers
25
-
26
- @@cdn_options = options
27
29
  end
28
30
 
29
31
  def registered
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module CDN
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-cdn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leigh McCulloch
@@ -161,6 +161,7 @@ files:
161
161
  - Gemfile
162
162
  - Guardfile
163
163
  - LICENSE
164
+ - README-cloudflare-pagerule-example.png
164
165
  - README.md
165
166
  - Rakefile
166
167
  - features/support/env.rb