middleman-cdn 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README-cloudflare-pagerule-example.png +0 -0
- data/README.md +84 -21
- data/lib/middleman-cdn/extension.rb +6 -4
- data/lib/middleman-cdn/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 69067babbcf6c181de78867c0a26cd0419f1cd7f
|
|
4
|
+
data.tar.gz: 9a2adde88d7fce458d9c04d29dd48728403c708d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f353a06b8b40e21e040c5797c504f15afe500b5264ea476e91ba587f7ea26e2e8114aac2bfc9bea10f03c5dab5886d7630cca98ecbc6534557268154c9b01ac
|
|
7
|
+
data.tar.gz: 2627680904f589d2901a5732549c19105ea017dcbafcac74f986efd57f1747c3e1ab194f0d8bba957c8fa0d1c848ab695b818eb380fe64ea84e6e8aa3a8eb835
|
|
Binary file
|
data/README.md
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
# Middleman CDN [](https://travis-ci.org/leighmcculloch/middleman-cdn) [](https://gemnasium.com/leighmcculloch/middleman-cdn)
|
|
2
|
-
A
|
|
3
|
-
on
|
|
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
|
-
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
|
37
|
-
|
|
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: '...',
|
|
42
|
-
email: 'you@example.com',
|
|
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: [
|
|
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
|
|
55
|
+
cdn.after_build = true # default is false
|
|
53
56
|
end
|
|
54
57
|
```
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
128
|
+
Invalidate manually using:
|
|
71
129
|
```bash
|
|
72
130
|
bundle exec middleman invalidate
|
|
73
131
|
```
|
|
74
132
|
|
|
75
|
-
Or
|
|
133
|
+
Or:
|
|
76
134
|
```bash
|
|
77
135
|
bundle exec middleman inv
|
|
78
136
|
```
|
|
79
137
|
|
|
80
|
-
##
|
|
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
|
+

|
|
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
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
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.
|
|
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
|