jekyll-imgproxy-tag 0.1.0
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 +7 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +109 -0
- data/LICENSE.md +19 -0
- data/README.md +151 -0
- data/Rakefile +21 -0
- data/jekyll-imgproxy-tag.gemspec +29 -0
- data/lib/jekyll/imgproxy/tag/errors.rb +30 -0
- data/lib/jekyll/imgproxy/tag/hmac_builder.rb +37 -0
- data/lib/jekyll/imgproxy/tag/imgproxy_config.rb +44 -0
- data/lib/jekyll/imgproxy/tag/path_builder.rb +89 -0
- data/lib/jekyll/imgproxy/tag/url_generator.rb +26 -0
- data/lib/jekyll/imgproxy/tag.rb +30 -0
- data/lib/jekyll-imgproxy-tag.rb +9 -0
- metadata +141 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4986a8d138622cab25b06efb7716d58786a2dd34e646f6ed2c34c94d79d4eda5
|
|
4
|
+
data.tar.gz: 9d4fd300c70729f06a9df38ea742bba7ea7f0428664fb542a1d1025063e2c6be
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 34d27de575af077407197a0e3c9f1e518d5c6b3a8f006d9feaa84ec1932ff2c4243571dd2da87477e81290e4d2ee4214bcf04363f0424bf5975402d87af7e42a
|
|
7
|
+
data.tar.gz: 28c1efba10ef21ff65f7941606633868b87e4a30cc0ec58dffa79ffa1cb918ffea7d7b54cf1ab238090b5739e924ad850f2fc9610e658d44205036254a8360cf
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
jekyll-imgproxy-tag (0.1.0)
|
|
5
|
+
jekyll
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
addressable (2.8.0)
|
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
12
|
+
byebug (11.1.3)
|
|
13
|
+
coderay (1.1.3)
|
|
14
|
+
colorator (1.1.0)
|
|
15
|
+
concurrent-ruby (1.1.10)
|
|
16
|
+
diff-lcs (1.5.0)
|
|
17
|
+
em-websocket (0.5.3)
|
|
18
|
+
eventmachine (>= 0.12.9)
|
|
19
|
+
http_parser.rb (~> 0)
|
|
20
|
+
eventmachine (1.2.7)
|
|
21
|
+
ffi (1.15.5)
|
|
22
|
+
forwardable-extended (2.6.0)
|
|
23
|
+
http_parser.rb (0.8.0)
|
|
24
|
+
i18n (1.10.0)
|
|
25
|
+
concurrent-ruby (~> 1.0)
|
|
26
|
+
io-console (0.5.11)
|
|
27
|
+
irb (1.4.1)
|
|
28
|
+
reline (>= 0.3.0)
|
|
29
|
+
jekyll (4.2.2)
|
|
30
|
+
addressable (~> 2.4)
|
|
31
|
+
colorator (~> 1.0)
|
|
32
|
+
em-websocket (~> 0.5)
|
|
33
|
+
i18n (~> 1.0)
|
|
34
|
+
jekyll-sass-converter (~> 2.0)
|
|
35
|
+
jekyll-watch (~> 2.0)
|
|
36
|
+
kramdown (~> 2.3)
|
|
37
|
+
kramdown-parser-gfm (~> 1.0)
|
|
38
|
+
liquid (~> 4.0)
|
|
39
|
+
mercenary (~> 0.4.0)
|
|
40
|
+
pathutil (~> 0.9)
|
|
41
|
+
rouge (~> 3.0)
|
|
42
|
+
safe_yaml (~> 1.0)
|
|
43
|
+
terminal-table (~> 2.0)
|
|
44
|
+
jekyll-sass-converter (2.2.0)
|
|
45
|
+
sassc (> 2.0.1, < 3.0)
|
|
46
|
+
jekyll-watch (2.2.1)
|
|
47
|
+
listen (~> 3.0)
|
|
48
|
+
kramdown (2.4.0)
|
|
49
|
+
rexml
|
|
50
|
+
kramdown-parser-gfm (1.1.0)
|
|
51
|
+
kramdown (~> 2.0)
|
|
52
|
+
liquid (4.0.3)
|
|
53
|
+
listen (3.7.1)
|
|
54
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
55
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
|
56
|
+
mercenary (0.4.0)
|
|
57
|
+
method_source (1.0.0)
|
|
58
|
+
pathutil (0.16.2)
|
|
59
|
+
forwardable-extended (~> 2.6)
|
|
60
|
+
pry (0.13.1)
|
|
61
|
+
coderay (~> 1.1)
|
|
62
|
+
method_source (~> 1.0)
|
|
63
|
+
pry-byebug (3.9.0)
|
|
64
|
+
byebug (~> 11.0)
|
|
65
|
+
pry (~> 0.13.0)
|
|
66
|
+
public_suffix (4.0.7)
|
|
67
|
+
rake (13.0.6)
|
|
68
|
+
rb-fsevent (0.11.1)
|
|
69
|
+
rb-inotify (0.10.1)
|
|
70
|
+
ffi (~> 1.0)
|
|
71
|
+
reline (0.3.1)
|
|
72
|
+
io-console (~> 0.5)
|
|
73
|
+
rexml (3.2.5)
|
|
74
|
+
rouge (3.29.0)
|
|
75
|
+
rspec (3.11.0)
|
|
76
|
+
rspec-core (~> 3.11.0)
|
|
77
|
+
rspec-expectations (~> 3.11.0)
|
|
78
|
+
rspec-mocks (~> 3.11.0)
|
|
79
|
+
rspec-core (3.11.0)
|
|
80
|
+
rspec-support (~> 3.11.0)
|
|
81
|
+
rspec-expectations (3.11.0)
|
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
83
|
+
rspec-support (~> 3.11.0)
|
|
84
|
+
rspec-mocks (3.11.1)
|
|
85
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
86
|
+
rspec-support (~> 3.11.0)
|
|
87
|
+
rspec-support (3.11.0)
|
|
88
|
+
rubygems-tasks (0.2.5)
|
|
89
|
+
irb (~> 1.0)
|
|
90
|
+
safe_yaml (1.0.5)
|
|
91
|
+
sassc (2.4.0)
|
|
92
|
+
ffi (~> 1.9)
|
|
93
|
+
terminal-table (2.0.0)
|
|
94
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
|
95
|
+
unicode-display_width (1.8.0)
|
|
96
|
+
|
|
97
|
+
PLATFORMS
|
|
98
|
+
ruby
|
|
99
|
+
|
|
100
|
+
DEPENDENCIES
|
|
101
|
+
bundler
|
|
102
|
+
jekyll-imgproxy-tag!
|
|
103
|
+
pry-byebug
|
|
104
|
+
rake
|
|
105
|
+
rspec (~> 3.0)
|
|
106
|
+
rubygems-tasks (~> 0.2)
|
|
107
|
+
|
|
108
|
+
BUNDLED WITH
|
|
109
|
+
2.2.22
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright 2022 Joel Oliveira
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
5
|
+
the Software without restriction, including without limitation the rights to
|
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
8
|
+
so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
jekyll-imgproxy-tag
|
|
2
|
+
===================
|
|
3
|
+
|
|
4
|
+
`jekyll-imgproxy-tag` is a jekyll plugin that provides a Liquid tag that
|
|
5
|
+
generates a fully secure, fully qualified url to an image asset stored on Amazon S3, and served via the [imgproxy] tool.
|
|
6
|
+
|
|
7
|
+
Example tag:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
{% imgproxy_url path: "/path/to/image.jpg", resizing_type: 'fill', width: 800, format: "webp" %}
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
[imgproxy]: https://imgproxy.net/
|
|
14
|
+
|
|
15
|
+
What's *imgproxy*?
|
|
16
|
+
------------------
|
|
17
|
+
|
|
18
|
+
> "imgproxy is the blazing fast and secure image processing tool".
|
|
19
|
+
|
|
20
|
+
It is an image optimizer written in Go that you can self-host as an alternative
|
|
21
|
+
to the larger commercial image optimization services like Imgix, Filestack,
|
|
22
|
+
Cloudinary, et al.
|
|
23
|
+
|
|
24
|
+
More information can be found on the [imgproxy website].
|
|
25
|
+
|
|
26
|
+
[imgproxy website]: https://www.imgproxy.net/
|
|
27
|
+
|
|
28
|
+
Ok, how do I start with this?
|
|
29
|
+
-----------------------------
|
|
30
|
+
|
|
31
|
+
Step 1: have imgproxy running somewhere. For now, this library assumes you are generating
|
|
32
|
+
secure addresses to the images you are serving, so you will need to take note of the **salt**
|
|
33
|
+
and **key** that you are setting for your imgproxy instance. Typically these are ENV's set
|
|
34
|
+
with the `IMGPROXY_KEY` and `IMGPROXY_SALT` keys.
|
|
35
|
+
|
|
36
|
+
Cool. I wrote those down. Now what?
|
|
37
|
+
-----------------------------------
|
|
38
|
+
|
|
39
|
+
In your Gemfile, add this gem:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
gem 'jekyll-imgproxy-tag'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
And do the `bundle install` dance.
|
|
46
|
+
|
|
47
|
+
***
|
|
48
|
+
|
|
49
|
+
Add the plugin to Jekyll's `_config.yml` file:
|
|
50
|
+
|
|
51
|
+
```yaml
|
|
52
|
+
plugins:
|
|
53
|
+
- jekyll-imgproxy-tag
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
*ALSO* add some required imgproxy config to that same `_config.yml` file:
|
|
57
|
+
|
|
58
|
+
```yaml
|
|
59
|
+
imgproxy:
|
|
60
|
+
base_url: https://url-to-your-imageproxy-server.com
|
|
61
|
+
key: the-very-long-KEY-that-is-set-in-your-imgproxy-instance
|
|
62
|
+
salt: the-very-long-SALT-that-is-set-in-your-imgproxy-instance
|
|
63
|
+
aws_bucket: your-s3-bucket-name
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
If you're checking that config file into source control then you might not want
|
|
67
|
+
to save that sort of sensitive information in your repo. As a result, this plugin
|
|
68
|
+
supports fetching environment variables by prepending `ENV_` in the values before
|
|
69
|
+
the name of your ENV's. If you use something like Netlify this is pretty handy.
|
|
70
|
+
|
|
71
|
+
```yaml
|
|
72
|
+
imgproxy:
|
|
73
|
+
base_url: https://url-to-your-imageproxy-server.com
|
|
74
|
+
key: ENV_IMGPROXY_KEY
|
|
75
|
+
salt: ENV_IMGPROXY_SALT
|
|
76
|
+
aws_bucket: ENV_AWS_BUCKET
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Ok. Now ... how do I *USE* this?
|
|
80
|
+
--------------------------------
|
|
81
|
+
|
|
82
|
+
Now you're ready to use this in your pages and/or posts. The most base liquid
|
|
83
|
+
tag usage is `{% imgproxy_url path: '/path/AFTER/your/bucket/dot.jpg' %}`. If
|
|
84
|
+
the sample object is in S3 bucket at `s3://my-bucket/images/photos/puppy.jpg`
|
|
85
|
+
then your path would be `/images/photos/puppy.jpg`. Woof 🐶.
|
|
86
|
+
|
|
87
|
+
The options you may pass in to transform and optimize your image, and the
|
|
88
|
+
corresponding information on their significance in imgproxy's docs, are as
|
|
89
|
+
follows:
|
|
90
|
+
|
|
91
|
+
* `resizing_type`
|
|
92
|
+
* example: `{% imgproxy_url path: '/path/image.jpg', resizing_type: 'fill' %}`
|
|
93
|
+
* Sample resizing types: `fit`, `fill`, `fill-down`, `force`, `auto`. Refer to the ...
|
|
94
|
+
* [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=resizing-type)
|
|
95
|
+
* `width`
|
|
96
|
+
* example: `{% imgproxy_url path: '/path/image.jpg', width: 960 %}`
|
|
97
|
+
* [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=width)
|
|
98
|
+
* `height`
|
|
99
|
+
* example: `{% imgproxy_url path: '/path/image.jpg', height: 400 %}`
|
|
100
|
+
* [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=height)
|
|
101
|
+
* `gravity`
|
|
102
|
+
* example: `{% imgproxy_url path: '/path/image.jpg', gravity: 'sm' %}`
|
|
103
|
+
* Note, there are many options. Provided option, `sm`, means "smart gravity".
|
|
104
|
+
* Please refer to the [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=gravity)
|
|
105
|
+
* `quality`
|
|
106
|
+
* example: `{% imgproxy_url path: '/path/image.jpg', quality: '85' %}`
|
|
107
|
+
* Note, this the resulting quality represented in percentage, from 0 to 100.
|
|
108
|
+
* [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=quality)
|
|
109
|
+
* `max_bytes`
|
|
110
|
+
* example: `{% imgproxy_url path: '/path/image.jpg', max_bytes: '100000' %}`
|
|
111
|
+
* Note, these are ***BYTES***, not Kilobytes. (100000 bytes == 100kB)
|
|
112
|
+
* [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=max-bytes)
|
|
113
|
+
* `cache_buster`
|
|
114
|
+
* example: `{% imgproxy_url path: '/path/image.jpg', cache_buster: 'string' %}`
|
|
115
|
+
* [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=cache-buster)
|
|
116
|
+
* `format`
|
|
117
|
+
* example: `{% imgproxy_url path: '/path/image.jpg', format: 'webp' %}`
|
|
118
|
+
* Sample formats: `png`, `jpg`, `webp`, `avif`, `gif`, etc. More info at ...
|
|
119
|
+
* [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=format)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
Are there any gotchas?
|
|
123
|
+
----------------------
|
|
124
|
+
|
|
125
|
+
Hey, I'm glad you asked. There are!
|
|
126
|
+
|
|
127
|
+
1. Currently **this plugin only works with assets that exist in Amazon S3**. Imgproxy needs to be set up to access.
|
|
128
|
+
2. Ensure that your instance of imgproxy has **sufficient (IAM) access to your S3 bucket(s) via the aws key and secret**.
|
|
129
|
+
3. If you're serving very large images, you may run into some issues. You can increase the max source image resolution via an environemt variable at your running imgproxy instance. For example `IMGPROXY_MAX_SRC_RESOLUTION=22.0` would allow for up to 22 megapixels. If it helps, there's [an online megapixels calculator here](https://toolstud.io/photo/megapixel.php?compare=video&calculate=uncompressed&width=1920&height=1080).
|
|
130
|
+
4. Setting `IMGPROXY_DEVELOPMENT_ERRORS_MODE=1` on your imgproxy instance will provide more detailed error messages.
|
|
131
|
+
|
|
132
|
+
For those of you setting up imgproxy yourself [there are many facets for configuration](https://github.com/imgproxy/imgproxy/blob/master/docs/configuration.md).
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
Development
|
|
136
|
+
===========
|
|
137
|
+
|
|
138
|
+
1. Clone this repo
|
|
139
|
+
2. `bundle`
|
|
140
|
+
3. `bundle exec rake`
|
|
141
|
+
4. New features should be paired with appropriate test coverage. (Please, and thank you.)
|
|
142
|
+
|
|
143
|
+
***
|
|
144
|
+
|
|
145
|
+
Currently not implemented but I would be thrilled to receive PR's or feedback on:
|
|
146
|
+
|
|
147
|
+
- [ ] Support for [plain source URL's](https://docs.imgproxy.net/generating_the_url?id=plain).
|
|
148
|
+
- [ ] Support for unsafe (unsigned) paths.
|
|
149
|
+
- [ ] Support for [serving local files](https://docs.imgproxy.net/serving_local_files?id=serving-local-files).
|
|
150
|
+
|
|
151
|
+
And, I'm always open for feedback - [@jayroh](https://twitter.com/jayroh) 🐦.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'rake/clean'
|
|
2
|
+
|
|
3
|
+
task(:default).clear
|
|
4
|
+
task default: [:spec]
|
|
5
|
+
|
|
6
|
+
desc 'Run tests'
|
|
7
|
+
task test: [:spec]
|
|
8
|
+
|
|
9
|
+
require 'rspec/core/rake_task'
|
|
10
|
+
desc 'Run RSpec'
|
|
11
|
+
RSpec::Core::RakeTask.new do |spec|
|
|
12
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
13
|
+
spec.rspec_opts = ['--color']
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
require 'rake'
|
|
17
|
+
|
|
18
|
+
require 'rubygems/tasks'
|
|
19
|
+
Gem::Tasks.new do |tasks|
|
|
20
|
+
tasks.console.command = 'pry'
|
|
21
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'jekyll-imgproxy-tag'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'jekyll-imgproxy-tag'
|
|
9
|
+
spec.version = Jekyll::Imgproxy::Tag::VERSION
|
|
10
|
+
spec.authors = ['Joel Oliveira']
|
|
11
|
+
spec.email = ['joel@jayroh.com']
|
|
12
|
+
|
|
13
|
+
spec.summary = 'jekyll plugin to generate urls to secure imgproxy images'
|
|
14
|
+
spec.description = 'jekyll plugin to generate urls to secure imgproxy images'
|
|
15
|
+
spec.homepage = 'https://github.com/jayroh/jekyll-imgproxy-tag'
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
|
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
19
|
+
spec.require_paths = ['lib']
|
|
20
|
+
spec.required_ruby_version = '>= 2.7.0'
|
|
21
|
+
|
|
22
|
+
spec.add_dependency 'jekyll'
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency 'bundler'
|
|
25
|
+
spec.add_development_dependency 'pry-byebug'
|
|
26
|
+
spec.add_development_dependency 'rake'
|
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
28
|
+
spec.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
|
29
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jekyll
|
|
4
|
+
module Imgproxy
|
|
5
|
+
class Tag
|
|
6
|
+
class Error < StandardError
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module Errors
|
|
10
|
+
class ConfigNotFound < Error
|
|
11
|
+
def message
|
|
12
|
+
'imgproxy namespace not found in Jekyll configuration'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class SaltNotSet < Error
|
|
17
|
+
'"salt" is not set in Jekyll imgproxy config'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class KeyNotSet < Error
|
|
21
|
+
'"key" is not set in Jekyll imgproxy config'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class BaseUrlNotSet < Error
|
|
25
|
+
'"base_url" not set in Jekyll Imgproxy config'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'openssl'
|
|
4
|
+
require 'base64'
|
|
5
|
+
|
|
6
|
+
module Jekyll
|
|
7
|
+
module Imgproxy
|
|
8
|
+
class Tag
|
|
9
|
+
class HmacBuilder
|
|
10
|
+
def initialize(config, path)
|
|
11
|
+
@config = config
|
|
12
|
+
@path = path
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def build
|
|
16
|
+
digest = OpenSSL::Digest.new('sha256')
|
|
17
|
+
hmac_digest = OpenSSL::HMAC.digest(digest, key, "#{salt}#{path}")
|
|
18
|
+
Base64.urlsafe_encode64(hmac_digest).tr('=', '')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
protected
|
|
22
|
+
|
|
23
|
+
attr_reader :config, :path
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def key
|
|
28
|
+
[config.key].pack("H*")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def salt
|
|
32
|
+
[config.salt].pack("H*")
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jekyll
|
|
4
|
+
module Imgproxy
|
|
5
|
+
class Tag
|
|
6
|
+
class ImgproxyConfig
|
|
7
|
+
attr_reader \
|
|
8
|
+
:base_url,
|
|
9
|
+
:key,
|
|
10
|
+
:salt,
|
|
11
|
+
:aws_bucket
|
|
12
|
+
|
|
13
|
+
def initialize
|
|
14
|
+
@base_url = fetch_config(:base_url)
|
|
15
|
+
@key = fetch_config(:key)
|
|
16
|
+
@salt = fetch_config(:salt)
|
|
17
|
+
@aws_bucket = fetch_config(:aws_bucket)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def fetch_config(key)
|
|
23
|
+
check_config!
|
|
24
|
+
|
|
25
|
+
value = imgproxy_config[key.to_s]
|
|
26
|
+
return ENV[value.gsub(/^ENV_/, '')] if value&.match?(/^ENV_/)
|
|
27
|
+
|
|
28
|
+
value
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def check_config!
|
|
32
|
+
raise Jekyll::Imgproxy::Tag::Errors::ConfigNotFound if imgproxy_config.nil?
|
|
33
|
+
raise Jekyll::Imgproxy::Tag::Errors::SaltNotSet if imgproxy_config['salt'].nil?
|
|
34
|
+
raise Jekyll::Imgproxy::Tag::Errors::KeyNotSet if imgproxy_config['key'].nil?
|
|
35
|
+
raise Jekyll::Imgproxy::Tag::Errors::BaseUrlNotSet if imgproxy_config['base_url'].nil?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def imgproxy_config
|
|
39
|
+
Jekyll.configuration['imgproxy']
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
|
|
5
|
+
module Jekyll
|
|
6
|
+
module Imgproxy
|
|
7
|
+
class Tag
|
|
8
|
+
class PathBuilder
|
|
9
|
+
def initialize(config, options)
|
|
10
|
+
@config = config
|
|
11
|
+
@options = options
|
|
12
|
+
@path = @options.delete('path')
|
|
13
|
+
|
|
14
|
+
@resizing_type = 'rs:fit'
|
|
15
|
+
@width = ':'
|
|
16
|
+
@height = ':'
|
|
17
|
+
@format = '.jpg'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def build
|
|
21
|
+
options.each { |key, value| send("#{key}=".to_sym, value) }
|
|
22
|
+
|
|
23
|
+
"/#{resizing_type}#{width}#{height}#{gravity}#{quality}#{max_bytes}#{cache_buster}/#{encoded_url}#{format}"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
protected
|
|
27
|
+
|
|
28
|
+
attr_reader \
|
|
29
|
+
:config,
|
|
30
|
+
:options,
|
|
31
|
+
:path,
|
|
32
|
+
:resizing_type,
|
|
33
|
+
:width,
|
|
34
|
+
:height,
|
|
35
|
+
:gravity,
|
|
36
|
+
:quality,
|
|
37
|
+
:max_bytes,
|
|
38
|
+
:cache_buster,
|
|
39
|
+
:format
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def encoded_url
|
|
44
|
+
Base64
|
|
45
|
+
.urlsafe_encode64(s3_url)
|
|
46
|
+
.tr('=', '')
|
|
47
|
+
.scan(/.{1,16}/)
|
|
48
|
+
.join('/')
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def s3_url
|
|
52
|
+
"s3://#{config.aws_bucket}#{path}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def resizing_type=(resizing_type)
|
|
56
|
+
@resizing_type = "rs:#{resizing_type}"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def format=(format)
|
|
60
|
+
@format = ".#{format}"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def width=(width)
|
|
64
|
+
@width = ":#{width}"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def height=(height)
|
|
68
|
+
@height = ":#{height}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def gravity=(gravity)
|
|
72
|
+
@gravity = "/g:#{gravity}"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def quality=(quality)
|
|
76
|
+
@quality = "/q:#{quality}"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def max_bytes=(max_bytes)
|
|
80
|
+
@max_bytes = "/mb:#{max_bytes}"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def cache_buster=(cache_buster)
|
|
84
|
+
@cache_buster = "/cb:#{cache_buster}"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jekyll
|
|
4
|
+
module Imgproxy
|
|
5
|
+
class Tag
|
|
6
|
+
class UrlGenerator
|
|
7
|
+
def initialize(config, options)
|
|
8
|
+
@config = config
|
|
9
|
+
@options = options
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def url
|
|
13
|
+
path = PathBuilder.new(config, options).build
|
|
14
|
+
hmac = HmacBuilder.new(config, path).build
|
|
15
|
+
signed_path = "/#{hmac}#{path}"
|
|
16
|
+
|
|
17
|
+
"#{config.base_url}#{signed_path}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
protected
|
|
21
|
+
|
|
22
|
+
attr_reader :config, :options
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jekyll
|
|
4
|
+
module Imgproxy
|
|
5
|
+
class Tag < ::Liquid::Tag
|
|
6
|
+
VERSION = '0.1.0'
|
|
7
|
+
|
|
8
|
+
def initialize(tag_name, raw_options, tokens)
|
|
9
|
+
super
|
|
10
|
+
@raw_options = raw_options
|
|
11
|
+
@options = {}
|
|
12
|
+
|
|
13
|
+
@raw_options.scan(::Liquid::TagAttributes) do |key, value|
|
|
14
|
+
@options[key] = value.gsub(/^['"]|['"]$/, '')
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def render(_context)
|
|
19
|
+
imgproxy_config = ImgproxyConfig.new
|
|
20
|
+
UrlGenerator.new(imgproxy_config, options).url
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
protected
|
|
24
|
+
|
|
25
|
+
attr_accessor :options
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Liquid::Template.register_tag('imgproxy_url', Jekyll::Imgproxy::Tag)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'jekyll'
|
|
4
|
+
require 'jekyll/imgproxy/tag'
|
|
5
|
+
require 'jekyll/imgproxy/tag/imgproxy_config'
|
|
6
|
+
require 'jekyll/imgproxy/tag/path_builder'
|
|
7
|
+
require 'jekyll/imgproxy/tag/hmac_builder'
|
|
8
|
+
require 'jekyll/imgproxy/tag/url_generator'
|
|
9
|
+
require 'jekyll/imgproxy/tag/errors'
|
metadata
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jekyll-imgproxy-tag
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Joel Oliveira
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2022-06-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: jekyll
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: pry-byebug
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rubygems-tasks
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0.2'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0.2'
|
|
97
|
+
description: jekyll plugin to generate urls to secure imgproxy images
|
|
98
|
+
email:
|
|
99
|
+
- joel@jayroh.com
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- ".rspec"
|
|
105
|
+
- Gemfile
|
|
106
|
+
- Gemfile.lock
|
|
107
|
+
- LICENSE.md
|
|
108
|
+
- README.md
|
|
109
|
+
- Rakefile
|
|
110
|
+
- jekyll-imgproxy-tag.gemspec
|
|
111
|
+
- lib/jekyll-imgproxy-tag.rb
|
|
112
|
+
- lib/jekyll/imgproxy/tag.rb
|
|
113
|
+
- lib/jekyll/imgproxy/tag/errors.rb
|
|
114
|
+
- lib/jekyll/imgproxy/tag/hmac_builder.rb
|
|
115
|
+
- lib/jekyll/imgproxy/tag/imgproxy_config.rb
|
|
116
|
+
- lib/jekyll/imgproxy/tag/path_builder.rb
|
|
117
|
+
- lib/jekyll/imgproxy/tag/url_generator.rb
|
|
118
|
+
homepage: https://github.com/jayroh/jekyll-imgproxy-tag
|
|
119
|
+
licenses:
|
|
120
|
+
- MIT
|
|
121
|
+
metadata: {}
|
|
122
|
+
post_install_message:
|
|
123
|
+
rdoc_options: []
|
|
124
|
+
require_paths:
|
|
125
|
+
- lib
|
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: 2.7.0
|
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
|
+
requirements:
|
|
133
|
+
- - ">="
|
|
134
|
+
- !ruby/object:Gem::Version
|
|
135
|
+
version: '0'
|
|
136
|
+
requirements: []
|
|
137
|
+
rubygems_version: 3.2.22
|
|
138
|
+
signing_key:
|
|
139
|
+
specification_version: 4
|
|
140
|
+
summary: jekyll plugin to generate urls to secure imgproxy images
|
|
141
|
+
test_files: []
|