jekyll-plugin-gkimagetag 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/Gemfile +2 -0
- data/LICENSE.txt +12 -0
- data/README.md +1 -0
- data/Rakefile +1 -0
- data/jekyll-plugin-gkimagetag.gemspec +25 -0
- data/lib/jekyll-plugin-gkimagetag.rb +224 -0
- data/lib/jekyll-plugin-gkimagetag/version.rb +6 -0
- data/screenshot.png +0 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dcf88c75c5436d9060efed6a34dd20a4f8821e08443bd020cadefec3a72bf152
|
4
|
+
data.tar.gz: a8dd487dec48b1f58280c9a5454df60d5a13287b4b43d7722964d629be2f5e5b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a786d26ca1eda843ab1694d8bd2873321ab6819481bc7e447cc8b60d0c5f1143327138eda884767c7504c471503c4a4745310f79e757e346ef7d75b5666096f3
|
7
|
+
data.tar.gz: 0a228630bd79b2d3d8172f26bf99e859c796ec360bde2e53dadee827e946f6ef7705794192005f58c0609c2df2f237f11bf92d4ebf89cd3b2563cc91e176299e
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Copyright (c) 2018 glueckkanja.com
|
2
|
+
|
3
|
+
The above copyright notice and this permission notice shall be included in
|
4
|
+
all copies or substantial portions of the Software.
|
5
|
+
|
6
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
7
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
8
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
9
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
10
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
11
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
12
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# jekyll-plugin-gkimagetag
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jekyll-plugin-gkimagetag/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jekyll-plugin-gkimagetag"
|
8
|
+
spec.version = Jekyll::Image::VERSION
|
9
|
+
spec.authors = ["@glueckkanja"]
|
10
|
+
spec.email = ["info@glueckkanja.com"]
|
11
|
+
|
12
|
+
spec.summary = "GK Jekyll Image Tag"
|
13
|
+
spec.homepage = "https://glueckkanja.com"
|
14
|
+
spec.license = "Nonstandard"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency 'jekyll', '~> 3.7'
|
20
|
+
spec.add_dependency 'fastimage', '~> 2.1'
|
21
|
+
spec.add_dependency 'mini_magick', '~> 4.8'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
# Title: Jekyll Image Tag // changed by GK
|
2
|
+
# Downloaded 2018-01-18 last changed Rob Wierzbowski committed on Nov 22, 2014
|
3
|
+
# Original Authors: Rob Wierzbowski : @robwierzbowski
|
4
|
+
#
|
5
|
+
# Description: Better images for Jekyll.
|
6
|
+
#
|
7
|
+
# Download: https://github.com/robwierzbowski/jekyll-image-tag
|
8
|
+
# Documentation: https://github.com/robwierzbowski/jekyll-image-tag/readme.md
|
9
|
+
# Issues: https://github.com/robwierzbowski/jekyll-image-tag/issues
|
10
|
+
#
|
11
|
+
# Syntax: {% image [preset or WxH] path/to/img.jpg [attr="value"] %}
|
12
|
+
# Example: {% image poster.jpg alt="The strange case of Dr. Jekyll" %}
|
13
|
+
# {% image gallery poster.jpg alt="The strange case of Dr. Jekyll" class="gal-img" data-selected %}
|
14
|
+
# {% image 350xAUTO poster.jpg alt="The strange case of Dr. Jekyll" class="gal-img" data-selected %}
|
15
|
+
#
|
16
|
+
# See the documentation for full configuration and usage instructions.
|
17
|
+
|
18
|
+
require 'fileutils'
|
19
|
+
require 'pathname'
|
20
|
+
require 'digest/md5'
|
21
|
+
require 'mini_magick'
|
22
|
+
require 'fastimage'
|
23
|
+
|
24
|
+
module Jekyll
|
25
|
+
|
26
|
+
class Image < Liquid::Tag
|
27
|
+
|
28
|
+
def initialize(tag_name, markup, tokens)
|
29
|
+
@markup = markup
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def render(context)
|
34
|
+
|
35
|
+
# Render any liquid variables in tag arguments and unescape template code
|
36
|
+
render_markup = Liquid::Template.parse(@markup).render(context).gsub(/\\\{\\\{|\\\{\\%/, '\{\{' => '{{', '\{\%' => '{%')
|
37
|
+
|
38
|
+
warn "Info (Image-Tag): ".yellow + "" + render_markup.to_s
|
39
|
+
|
40
|
+
# Gather settings
|
41
|
+
site = context.registers[:site]
|
42
|
+
debug = site.config['debug']
|
43
|
+
settings = site.config['image']
|
44
|
+
markup = /^(?:(?<preset>[^\s.:\/]+)\s+)?(?<image_src>[^\s]+\.[a-zA-Z0-9]{3,4})\s*(?<html_attr>[\s\S]+)?$/.match(render_markup)
|
45
|
+
preset = settings['presets'][ markup[:preset] ]
|
46
|
+
|
47
|
+
raise "Image Tag can't read this tag. Try {% image [preset or WxH] path/to/img.jpg [attr=\"value\"] %}." unless markup
|
48
|
+
|
49
|
+
# Assign defaults
|
50
|
+
settings['source'] ||= '.'
|
51
|
+
settings['output'] ||= 'generated'
|
52
|
+
|
53
|
+
# Prevent Jekyll from erasing our generated files
|
54
|
+
site.config['keep_files'] << settings['output'] unless site.config['keep_files'].include?(settings['output'])
|
55
|
+
|
56
|
+
# Process instance
|
57
|
+
instance = if preset
|
58
|
+
{
|
59
|
+
:width => preset['width'],
|
60
|
+
:height => preset['height'],
|
61
|
+
:src => markup[:image_src]
|
62
|
+
}
|
63
|
+
elsif dim = /^(?:(?<width>\d+)|auto)(?:x)(?:(?<height>\d+)|auto)$/i.match(markup[:preset])
|
64
|
+
{
|
65
|
+
:width => dim['width'],
|
66
|
+
:height => dim['height'],
|
67
|
+
:src => markup[:image_src]
|
68
|
+
}
|
69
|
+
else
|
70
|
+
{ :src => markup[:image_src] }
|
71
|
+
end
|
72
|
+
|
73
|
+
# Process html attributes
|
74
|
+
html_attr = if markup[:html_attr]
|
75
|
+
Hash[ *markup[:html_attr].scan(/(?<attr>[^\s="]+)(?:="(?<value>[^"]+)")?\s?/).flatten ]
|
76
|
+
else
|
77
|
+
{}
|
78
|
+
end
|
79
|
+
|
80
|
+
if preset && preset['attr']
|
81
|
+
html_attr = preset['attr'].merge(html_attr)
|
82
|
+
end
|
83
|
+
|
84
|
+
html_attr_string = html_attr.inject('') { |string, attrs|
|
85
|
+
if attrs[1]
|
86
|
+
string << "#{attrs[0]}=\"#{attrs[1]}\" "
|
87
|
+
else
|
88
|
+
string << "#{attrs[0]} "
|
89
|
+
end
|
90
|
+
}
|
91
|
+
|
92
|
+
# Raise some exceptions before we start expensive processing
|
93
|
+
raise "Image Tag can't find the \"#{markup[:preset]}\" preset. Check image: presets in _config.yml for a list of presets." unless preset || dim || markup[:preset].nil?
|
94
|
+
|
95
|
+
# Generate resized images
|
96
|
+
generated_src = generate_image(instance, site.source, site.dest, settings['source'], settings['output'], debug)
|
97
|
+
unless generated_src
|
98
|
+
return
|
99
|
+
end
|
100
|
+
# Generate resized images 2x
|
101
|
+
generated2x_src = File.join(generated_src.dirname.to_s + "/" + File.basename(generated_src, ".*") + "@2x" + generated_src.extname)
|
102
|
+
|
103
|
+
warn "Info (Image-Tag): ".yellow + "" + generated_src.to_s.green + "\n | ".yellow + generated2x_src.to_s.blue if debug
|
104
|
+
|
105
|
+
generated_src = File.join(site.baseurl, generated_src) unless site.baseurl.empty?
|
106
|
+
generated2x_src = File.join(site.baseurl, generated2x_src) unless site.baseurl.empty?
|
107
|
+
|
108
|
+
markup_width = if instance[:width]
|
109
|
+
"width=\"#{instance[:width]}\""
|
110
|
+
end
|
111
|
+
# Return the markup!
|
112
|
+
"<img src=\"#{generated_src}\" srcset=\"#{generated_src} 1x, #{generated2x_src} 2x\" #{markup_width} #{html_attr_string}>"
|
113
|
+
end
|
114
|
+
|
115
|
+
def generate_image(instance, site_source, site_dest, image_source, image_dest, debug)
|
116
|
+
|
117
|
+
MiniMagick.configure do |config|
|
118
|
+
config.whiny = false
|
119
|
+
end
|
120
|
+
image_source_path = File.join(site_source, image_source, instance[:src])
|
121
|
+
unless File.exists?image_source_path
|
122
|
+
puts "Missing: #{image_source_path}"
|
123
|
+
return false
|
124
|
+
end
|
125
|
+
|
126
|
+
image = MiniMagick::Image.open(image_source_path)
|
127
|
+
digest = Digest::MD5.hexdigest(image.to_blob).slice!(0..5)
|
128
|
+
|
129
|
+
image_dir = File.dirname(instance[:src])
|
130
|
+
ext = File.extname(instance[:src])
|
131
|
+
basename = File.basename(instance[:src], ext)
|
132
|
+
|
133
|
+
orig_width = image[:width].to_f
|
134
|
+
orig_height = image[:height].to_f
|
135
|
+
orig_ratio = orig_width/orig_height
|
136
|
+
|
137
|
+
gen_width = if instance[:width]
|
138
|
+
instance[:width].to_f * 2
|
139
|
+
elsif instance[:height]
|
140
|
+
orig_ratio * instance[:height].to_f * 2
|
141
|
+
else
|
142
|
+
orig_width
|
143
|
+
end
|
144
|
+
gen_height = if instance[:height]
|
145
|
+
instance[:height].to_f * 2
|
146
|
+
elsif instance[:width]
|
147
|
+
instance[:width].to_f / orig_ratio * 2
|
148
|
+
else
|
149
|
+
orig_height
|
150
|
+
end
|
151
|
+
gen_ratio = gen_width/gen_height
|
152
|
+
|
153
|
+
# Don't allow upscaling. If the image is smaller than the requested dimensions, recalculate.
|
154
|
+
if orig_width < gen_width || orig_height < gen_height
|
155
|
+
undersize = true
|
156
|
+
gen_width = if orig_ratio < gen_ratio then orig_width else orig_height * gen_ratio end
|
157
|
+
gen_height = if orig_ratio > gen_ratio then orig_height else orig_width/gen_ratio end
|
158
|
+
end
|
159
|
+
|
160
|
+
#2x
|
161
|
+
gen_name = "#{basename}-#{gen_width.round}x#{gen_height.round}-#{digest}@2x#{ext}"
|
162
|
+
gen_dest_dir = File.join(site_dest, image_dest, image_dir)
|
163
|
+
gen_dest_file = File.join(gen_dest_dir, gen_name)
|
164
|
+
|
165
|
+
# Generate resized files
|
166
|
+
unless File.exists?(gen_dest_file)
|
167
|
+
|
168
|
+
warn "Warning:".yellow + " #{instance[:src]} is smaller than the requested output file. It will be resized without upscaling." if undersize
|
169
|
+
|
170
|
+
# If the destination directory doesn't exist, create it
|
171
|
+
FileUtils.mkdir_p(gen_dest_dir) unless File.exist?(gen_dest_dir)
|
172
|
+
|
173
|
+
# Let people know their images are being generated
|
174
|
+
puts "Generating #{gen_name}" if !debug
|
175
|
+
|
176
|
+
# Scale and crop
|
177
|
+
image.combine_options do |i|
|
178
|
+
i.resize "#{gen_width}x#{gen_height}^"
|
179
|
+
i.gravity "center"
|
180
|
+
i.crop "#{gen_width}x#{gen_height}+0+0"
|
181
|
+
#i.layers "Optimize"
|
182
|
+
end
|
183
|
+
|
184
|
+
image.write gen_dest_file
|
185
|
+
end
|
186
|
+
|
187
|
+
#1x
|
188
|
+
gen_name = "#{basename}-#{gen_width.round}x#{gen_height.round}-#{digest}#{ext}"
|
189
|
+
gen_dest_dir = File.join(site_dest, image_dest, image_dir)
|
190
|
+
gen_dest_file = File.join(gen_dest_dir, gen_name)
|
191
|
+
|
192
|
+
gen_width = gen_width / 2
|
193
|
+
gen_height = gen_height / 2
|
194
|
+
|
195
|
+
# Generate resized files
|
196
|
+
unless File.exists?(gen_dest_file)
|
197
|
+
|
198
|
+
warn "Warning:".yellow + " #{instance[:src]} is smaller than the requested output file. It will be resized without upscaling." if undersize
|
199
|
+
|
200
|
+
# If the destination directory doesn't exist, create it
|
201
|
+
FileUtils.mkdir_p(gen_dest_dir) unless File.exist?(gen_dest_dir)
|
202
|
+
|
203
|
+
# Let people know their images are being generated
|
204
|
+
puts "Generating #{gen_name}" if !debug
|
205
|
+
|
206
|
+
# Scale and crop
|
207
|
+
image.combine_options do |i|
|
208
|
+
i.resize "#{gen_width}x#{gen_height}^"
|
209
|
+
i.gravity "center"
|
210
|
+
i.crop "#{gen_width}x#{gen_height}+0+0"
|
211
|
+
#i.layers "Optimize"
|
212
|
+
end
|
213
|
+
|
214
|
+
image.write gen_dest_file
|
215
|
+
end
|
216
|
+
|
217
|
+
# Return path relative to the site root for html
|
218
|
+
Pathname.new(File.join('/', image_dest, image_dir, gen_name)).cleanpath
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
Liquid::Template.register_tag('image', Jekyll::Image)
|
data/screenshot.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-plugin-gkimagetag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "@glueckkanja"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-05 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: '3.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fastimage
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mini_magick
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- info@glueckkanja.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- Gemfile
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- jekyll-plugin-gkimagetag.gemspec
|
95
|
+
- lib/jekyll-plugin-gkimagetag.rb
|
96
|
+
- lib/jekyll-plugin-gkimagetag/version.rb
|
97
|
+
- screenshot.png
|
98
|
+
homepage: https://glueckkanja.com
|
99
|
+
licenses:
|
100
|
+
- Nonstandard
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.7.2
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: GK Jekyll Image Tag
|
122
|
+
test_files: []
|