shi-jekyll-images 0.1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c46efb41167a462a3dbdbb688427e3fce17d24c050185a064834547cf2299932
4
+ data.tar.gz: cb8c641d7a054a509a6d4dee65cb831dd9c860bf52ee1e894df3dd3420937fb3
5
+ SHA512:
6
+ metadata.gz: '001189f90de0599f61f721252f4838491459c7a21ae07b8cc8db62b3fe57b29310d78aa76279eda0bb740574d73da7a98c130899a4f044775b0ee60f1648fea9'
7
+ data.tar.gz: c712f7009557cf0d3c687d345d800c75c264177a085d09ccd200d46d43258871788eb49e0408d35460c44a5f6a2030d6b19dd08697827a301dae44a742c458b2
data/.rufo ADDED
@@ -0,0 +1,6 @@
1
+
2
+ align_case_when true
3
+ parens_in_def :dynamic
4
+ align_chained_calls true
5
+ trailing_commas false
6
+ quote_style :single
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in shi-jekyll-images.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shi-jekyll-images (0.1.0)
5
+ jekyll (>= 4.0, < 5.0)
6
+ liquid (~> 4.0)
7
+ shi-args (~> 0.3.3.5)
8
+ shi-tools (~> 0.1.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.8.1)
14
+ public_suffix (>= 2.0.2, < 6.0)
15
+ colorator (1.1.0)
16
+ concurrent-ruby (1.1.10)
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
+ google-protobuf (3.21.12-x86_64-linux)
24
+ http_parser.rb (0.8.0)
25
+ i18n (1.12.0)
26
+ concurrent-ruby (~> 1.0)
27
+ jekyll (4.3.1)
28
+ addressable (~> 2.4)
29
+ colorator (~> 1.0)
30
+ em-websocket (~> 0.5)
31
+ i18n (~> 1.0)
32
+ jekyll-sass-converter (>= 2.0, < 4.0)
33
+ jekyll-watch (~> 2.0)
34
+ kramdown (~> 2.3, >= 2.3.1)
35
+ kramdown-parser-gfm (~> 1.0)
36
+ liquid (~> 4.0)
37
+ mercenary (>= 0.3.6, < 0.5)
38
+ pathutil (~> 0.9)
39
+ rouge (>= 3.0, < 5.0)
40
+ safe_yaml (~> 1.0)
41
+ terminal-table (>= 1.8, < 4.0)
42
+ webrick (~> 1.7)
43
+ jekyll-sass-converter (3.0.0)
44
+ sass-embedded (~> 1.54)
45
+ jekyll-watch (2.2.1)
46
+ listen (~> 3.0)
47
+ kramdown (2.4.0)
48
+ rexml
49
+ kramdown-parser-gfm (1.1.0)
50
+ kramdown (~> 2.0)
51
+ liquid (4.0.3)
52
+ listen (3.7.1)
53
+ rb-fsevent (~> 0.10, >= 0.10.3)
54
+ rb-inotify (~> 0.9, >= 0.9.10)
55
+ mercenary (0.4.0)
56
+ pathutil (0.16.2)
57
+ forwardable-extended (~> 2.6)
58
+ public_suffix (5.0.1)
59
+ rb-fsevent (0.11.2)
60
+ rb-inotify (0.10.1)
61
+ ffi (~> 1.0)
62
+ rexml (3.2.5)
63
+ rouge (4.0.1)
64
+ safe_yaml (1.0.5)
65
+ sass-embedded (1.57.1-x86_64-linux-gnu)
66
+ google-protobuf (~> 3.21)
67
+ shi-args (0.3.3.5)
68
+ jekyll (>= 4.0, < 5.0)
69
+ liquid (~> 4.0)
70
+ shi-tools (~> 0.1.0)
71
+ shi-tools (0.1.0)
72
+ terminal-table (3.0.2)
73
+ unicode-display_width (>= 1.1.1, < 3)
74
+ unicode-display_width (2.4.2)
75
+ webrick (1.7.0)
76
+
77
+ PLATFORMS
78
+ x86_64-linux
79
+
80
+ DEPENDENCIES
81
+ shi-jekyll-images!
82
+
83
+ BUNDLED WITH
84
+ 2.4.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Иван Шихалев
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ [![Gem Version](https://badge.fury.io/rb/shi-jekyll-images.svg)](https://badge.fury.io/rb/shi-jekyll-images)
2
+
3
+ # Shi::Jekyll::Images
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/shi/jekyll/images`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'shi-jekyll-images'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install shi-jekyll-images
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/shi-jekyll-images.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shi::Jekyll::Images::Config
4
+ def site_config
5
+ @@site_config ||= Jekyll::configuration || {}
6
+ @@site_config
7
+ end
8
+
9
+ def config
10
+ @@config ||= Jekyll::configuration['shi_images'] || {}
11
+ @@config
12
+ end
13
+
14
+ def get_value page, name
15
+ result = page.data[name]
16
+ if result == nil
17
+ layout_name = page.data['layout']
18
+ if layout_name
19
+ layout_object = site.layouts[page.data['layout']]
20
+ if layout_object
21
+ result = layout_object.data[name]
22
+ end
23
+ end
24
+ end
25
+ if result == nil
26
+ result = config[name]
27
+ end
28
+ result
29
+ end
30
+
31
+ def site
32
+ Jekyll::sites.first
33
+ end
34
+
35
+ def path_by_page page
36
+ target_root = config['target_root'] || 'img'
37
+ result = target_root
38
+ by_url = true
39
+ if page.respond_to?(:date) && page.date != nil
40
+ result = Jekyll::PathManager::join result, page.date.strftime('%Y/%m/%d')
41
+ by_url = false
42
+ end
43
+ if page.respond_to?(:data) && page.data['slug'] != nil
44
+ result = Jekyll::PathManager::join result, page.data['slug']
45
+ by_url = false
46
+ end
47
+ if by_url
48
+ if page.respond_to?(:url) && page.url != nil
49
+ result = Jekyll::PathManager::join result, page.url
50
+ else
51
+ raise ArgumentError, "Invalid Page object: #{page.inspect}"
52
+ end
53
+ end
54
+ result
55
+ end
56
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'version'
4
+
5
+ class Shi::Jekyll::FigureBlock < Liquid::Block
6
+ DEFAULT_WIDTH = {
7
+ :right => 320,
8
+ :left => 320,
9
+ :center => 600
10
+ }
11
+
12
+ def render context
13
+ images_args = {}
14
+ args = Shi::Args::Params::parse context, @markup
15
+ args.each_attribute do |key, value|
16
+ if key.to_s =~ /^img_(?<name>\w+)/
17
+ images_args[$~[:name].intern] = value
18
+ end
19
+ end
20
+
21
+ text = context.stack do
22
+ context['extra_args'] = images_args
23
+ super context
24
+ end
25
+
26
+ place = args[:place]
27
+ if place.nil?
28
+ place = :right if args[:right]
29
+ place ||= :left if args[:left]
30
+ place ||= :center
31
+ else
32
+ place = place.intern
33
+ end
34
+ width = args[:width] || Shi::Args::Value::Measure::px(DEFAULT_WIDTH[place])
35
+
36
+ cls = '__figure'
37
+ cls += ' ' + args[:class] if args[:class]
38
+ cls += " __#{place}"
39
+
40
+ style = "max-width:#{width.value};"
41
+ style += args[:style] if args[:style]
42
+
43
+ id = args[:id]
44
+
45
+ attrs = "class=\"#{cls}\" style=\"#{style}\""
46
+ attrs += " id=\"#{id}\"" if id
47
+
48
+ caption_position = args[:caption_position]&.intern || :bottom
49
+
50
+ caption = args[:caption]
51
+ if text.gsub!(/^\s*#\s*(?<caption>.*?)(\n|$)/, '')
52
+ caption ||= $~[:caption]
53
+ end
54
+
55
+ wrp_class = '__figure_wrapper'
56
+ wrp_class += ' ' + args[:wrp_class] if args[:wrp_class]
57
+ wrp_attrs = "class=\"#{wrp_class}\""
58
+ wrp_attrs = " style=\"#{args[:wrp_style]}\"" if args[:wrp_style]
59
+ if caption
60
+ cap_attrs = ''
61
+ cap_attrs += " class=\"#{args[:cap_class]}\"" if args[:cap_class]
62
+ cap_attrs += " style=\"#{args[:cap_style]}\"" if args[:cap_style]
63
+ if caption_position == :bottom
64
+ text = "<div #{wrp_attrs}>#{text}</div><figcaption#{cap_attrs} markdown=\"span\">#{caption}</figcaption>"
65
+ else
66
+ text = "<figcaption#{cap_attrs} markdown=\"span\">#{caption}</figcaption><div #{wrp_attrs}>#{text}</div>"
67
+ end
68
+ else
69
+ text = "<div #{wrp_attrs}>#{text}</div>"
70
+ end
71
+
72
+ "<figure #{attrs} markdown=\"0\">#{text}</figure>"
73
+ end
74
+ end
75
+
76
+ Liquid::Template.register_tag 'figure', Shi::Jekyll::FigureBlock
@@ -0,0 +1,194 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'version'
4
+ require_relative 'config'
5
+
6
+ module Shi::Jekyll::Images::File
7
+ class << self
8
+ def create page, source, bounds, crop
9
+ type = File.extname source.relative_path
10
+ if type.downcase == '.svg'
11
+ Shi::Jekyll::Images::SVGFile::create page, source
12
+ else
13
+ Shi::Jekyll::Images::WebPFile::create page, source, bounds, crop
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ class Shi::Jekyll::Images::WebPFile < Jekyll::StaticFile
20
+ include Shi::Jekyll::Images::Config
21
+
22
+ class << self
23
+ include Shi::Jekyll::Images::Config
24
+
25
+ def name_by_source source, bounds, crop
26
+ result = source.basename
27
+ result += "-#{bounds}" if bounds && !['SOURCE', 'ORIGINAL', 'ORIGIN', 'NONE'].include?(bounds.upcase)
28
+ result += "-#{Jekyll::Utils::slugify(crop)}" if crop
29
+ result += '.webp'
30
+ result
31
+ end
32
+
33
+ def path page, source, bounds, crop
34
+ Jekyll::PathManager::join path_by_page(page), name_by_source(source, bounds, crop)
35
+ end
36
+
37
+ def make_key source, bounds, crop
38
+ result = source.relative_path
39
+ result += "@#{bounds}" if bounds
40
+ result += "@#{crop}" if crop
41
+ Jekyll::PathManager::join '', result
42
+ end
43
+
44
+ def default_bounds page
45
+ get_value(page, 'image_bounds') || 'ORIGINAL'
46
+ end
47
+
48
+ def create page, source, bounds, crop
49
+ bounds ||= default_bounds(page)
50
+ return source if source.write? && (['SOURCE', 'ORIGINAL', 'ORIGIN', 'NONE'].include?(bounds.upcase)) && crop.nil?
51
+
52
+ @@created ||= {}
53
+ key = make_key source, bounds, crop
54
+ result = @@created[key]
55
+ if result == nil
56
+ result = new path(page, source, bounds, crop), source, bounds, crop
57
+ @@created[key] = result
58
+ end
59
+ if !site.static_files.include?(result)
60
+ site.static_files << result
61
+ end
62
+ result
63
+ end
64
+
65
+ private :new
66
+ private :name_by_source, :path, :make_key, :default_bounds
67
+ end
68
+
69
+ def initialize path, source, bounds, crop
70
+ @wp_path = path
71
+ @wp_source = source
72
+ @wp_bounds = bounds
73
+ @wp_crop = crop
74
+ super site, site.source, File.dirname(path), File.basename(path)
75
+ end
76
+
77
+ def modified?
78
+ true
79
+ end
80
+
81
+ def write?
82
+ true
83
+ end
84
+
85
+ def cropping crop
86
+ if crop
87
+ "-crop '#{crop}' +repage -flatten"
88
+ else
89
+ ''
90
+ end
91
+ end
92
+
93
+ def resizing bounds
94
+ command = '-filter Lanczos2Sharp -resize'
95
+ case bounds.upcase
96
+ when 'HD', '720P'
97
+ "#{command} '1280x720>'"
98
+ when 'FULLHD', 'FHD', '1080P'
99
+ "#{command} '1920x1080>'"
100
+ when 'WYXGA', '1200P'
101
+ "#{command} '1920x1200>'"
102
+ when '2K', 'QUADHD', 'QHD', 'WQHD', '1440P'
103
+ "#{command} '2560x1440>'"
104
+ when '4K', 'ULTRAHD', 'UHD', '2160P'
105
+ "#{command} '3840x2160>'"
106
+ when '5K', '2880P'
107
+ "#{command} '5120x2880>'"
108
+ when '8K', '4320P'
109
+ "#{command} '7680x4320>'"
110
+ when 'SOURCE', 'ORIGINAL', 'ORIGIN', 'NONE'
111
+ ''
112
+ else
113
+ "#{command} '#{bounds}>'"
114
+ end
115
+ end
116
+
117
+ def qualiting
118
+ '-strip -quality 80 -define webp:auto-filter=true'
119
+ end
120
+
121
+ def write dest
122
+ tgt_path = destination dest
123
+ src_path = File::join site.source, @wp_source.relative_path
124
+
125
+ FileUtils::mkdir_p(File.dirname(tgt_path))
126
+ FileUtils::rm(tgt_path) if File.exist?(tgt_path)
127
+ cmd = "convert '#{src_path}' #{cropping(@wp_crop)} #{resizing(@wp_bounds)} #{qualiting} '#{tgt_path}'"
128
+ system(cmd, exception: true)
129
+
130
+ true
131
+ end
132
+
133
+ private :cropping, :resizing, :qualiting
134
+ end
135
+
136
+ class Shi::Jekyll::Images::SVGFile < Jekyll::StaticFile
137
+ include Shi::Jekyll::Images::Config
138
+
139
+ class << self
140
+ include Shi::Jekyll::Images::Config
141
+
142
+ def path page, source
143
+ Jekyll::PathManager::join path_by_page(page), source.name
144
+ end
145
+
146
+ def make_key source
147
+ Jekyll::PathManager::join '', source.relative_path
148
+ end
149
+
150
+ def create page, source
151
+ return source if source.write?
152
+
153
+ @@created ||= {}
154
+ key = make_key source
155
+ result = @@created[key]
156
+ if result == nil
157
+ result = new path(page, source), source
158
+ @@created[key] = result
159
+ end
160
+ if !site.static_files.include?(result)
161
+ site.static_files << result
162
+ end
163
+ result
164
+ end
165
+
166
+ private :new
167
+ private :path, :make_key
168
+ end
169
+
170
+ def initialize path, source
171
+ @wp_path = path
172
+ @wp_source = source
173
+ super site, site.source, File.dirname(path), File.basename(path)
174
+ end
175
+
176
+ def modified?
177
+ true
178
+ end
179
+
180
+ def write?
181
+ true
182
+ end
183
+
184
+ def write dest
185
+ tgt_path = destination dest
186
+ src_path = File::join site.source, @wp_source.relative_path
187
+
188
+ FileUtils::mkdir_p(File.dirname(tgt_path))
189
+ FileUtils::rm(tgt_path) if File.exist?(tgt_path)
190
+ FileUtils::cp(src_path, tgt_path)
191
+
192
+ true
193
+ end
194
+ end
@@ -0,0 +1,216 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'version'
4
+ require_relative 'files'
5
+
6
+ class Shi::Jekyll::ImageTag < Liquid::Tag
7
+ include Shi::Tools
8
+
9
+ def width_to_bounds width
10
+ if Shi::Args::Value::Measure === width
11
+ width.to_px.to_s
12
+ else
13
+ width.to_s
14
+ end
15
+ end
16
+
17
+ DEFAULT_THUMB_BOUNDS = '320'
18
+ DEFAULT_WIDTH = Shi::Args::Value::Measure::px(320)
19
+
20
+ def thumb_bounds context, args, extra
21
+ bounds = args[:thumb_bounds] || extra[:thumb_bounds]
22
+ width = args[:width] || extra[:width]
23
+ if width && !bounds
24
+ bounds = width_to_bounds width
25
+ end
26
+ bounds ||= lookup_with(context, 'thumb_bounds', ['page', 'layout', 'site.shi_images']) || DEFAULT_THUMB_BOUNDS
27
+ bounds
28
+ end
29
+
30
+ def clean_path path
31
+ path.split(/\/?#/)[0]
32
+ end
33
+
34
+ def render context
35
+ args = Shi::Args::Params::parse context, @markup
36
+ extra_args = context['extra_args'] || {}
37
+
38
+ source = args[:src] || args[:source]
39
+ if source == nil && Jekyll::StaticFile === args[0]
40
+ source = args[0]
41
+ end
42
+ if !Jekyll::StaticFile === source
43
+ raise ArgumentError, "Invalid source: #{source.inspect}!"
44
+ end
45
+
46
+ link = args[:link]
47
+ link = false if args[:no_link]
48
+ link = true if link == nil
49
+ # if link == false only thumbnail needed
50
+
51
+ site = context.registers[:site]
52
+ page_path = clean_path(context['page.path'])
53
+ if page_path == nil
54
+ p context.registers[:page]
55
+ end
56
+ page = site.documents.find { |d| d.relative_path == page_path }
57
+ page ||= site.pages.find { |p| p.relative_path == page_path }
58
+
59
+ gen_big = false
60
+ href = if link == false # nothing
61
+ nil
62
+ elsif Jekyll::StaticFile === link && !link.write? # uncopyable static file => picture
63
+ bounds = args[:bounds] || extra_args[:bounds]
64
+ Jekyll::PathManager::join '', Shi::Jekyll::Images::File::create(page, link, bounds, nil).url
65
+ elsif link.respond_to?(:url) && link.url # document, page or static file
66
+ Jekyll::PathManager::join '', link.url
67
+ elsif String === link # external link
68
+ link
69
+ elsif link == true # generated big picture
70
+ gen_big = true
71
+ bounds = args[:bounds] || extra_args[:bounds]
72
+ Jekyll::PathManager::join '', Shi::Jekyll::Images::File::create(page, source, bounds, nil).url
73
+ else
74
+ raise ArgumentError, "Invalid link: #{link.inspect}!"
75
+ end
76
+
77
+ thumb = args[:thumb]
78
+ thumb = false if args[:no_thumb]
79
+ thumb = true if thumb == nil
80
+ # if thumb == false use full size as thumbnail
81
+
82
+ if !gen_big && !thumb
83
+ raise ArgumentError, "You can't disable large image and thumbnail at the same time!"
84
+ end
85
+
86
+ src = if thumb
87
+ bounds = thumb_bounds context, args, extra_args
88
+ crop = args[:crop] || extra_args[:crop]
89
+ Shi::Jekyll::Images::File::create(page, source, bounds, crop).url
90
+ else
91
+ href
92
+ end
93
+ src = Jekyll::PathManager::join '', src
94
+
95
+ cls = '__image'
96
+ cls += ' ' + args[:class] if args[:class]
97
+ cls += ' ' + extra_args[:class] if extra_args[:class]
98
+
99
+ width = args[:width] || extra_args[:width] || DEFAULT_WIDTH
100
+
101
+ style = ""
102
+ style += extra_args[:style] if extra_args[:style]
103
+ style += args[:style] if args[:style]
104
+
105
+ shape = args[:shape] || extra_args[:shape]
106
+ case shape
107
+ when Jekyll::StaticFile
108
+ shape_url = if shape.write?
109
+ shape.url
110
+ else
111
+ bounds = thumb_bounds context, args, extra_args
112
+ crop = args[:crop] || extra_args[:crop]
113
+ Jekyll::PathManager::join '', Shi::Jekyll::Images::File::create(page, shape, bounds, crop).url
114
+ end
115
+ style += "shape-outside:url(#{shape_url});"
116
+ when String
117
+ cls += " __shape_#{shape}"
118
+ when true
119
+ style += "shape-outside:url(#{src});"
120
+ end
121
+
122
+ caption = args[:caption]
123
+ title = args[:title] || caption
124
+ alt = args[:alt] || title
125
+ id = args[:id]
126
+
127
+ attrs = "class=\"#{cls}\""
128
+ attrs += " style=\"#{style}\"" if style && !style.empty?
129
+ attrs += " alt=\"#{alt}\"" if alt
130
+ attrs += " title=\"#{title}\"" if title
131
+ attrs += " id=\"#{id}\""
132
+
133
+ figure = args[:figure]
134
+ if figure && !extra_args.empty?
135
+ raise ArgumentError, 'Nested figures not allowed!'
136
+ end
137
+
138
+ result = ''
139
+ if figure
140
+ fig_class = '__figure __implicit_figure'
141
+ place = args[:place]
142
+ if place == 'right' || args[:right]
143
+ fig_class += ' __right'
144
+ elsif place == 'left' || args[:left]
145
+ fig_class += ' __left'
146
+ else
147
+ fig_class += ' __center'
148
+ end
149
+ fig_class += ' ' + args[:fig_class] if args[:fig_class]
150
+ fig_style = "max-width:#{width.value};"
151
+ fig_style += args[:fig_style] if args[:fig_style]
152
+ case shape
153
+ when Jekyll::StaticFile
154
+ shape_url = if shape.write?
155
+ shape.url
156
+ else
157
+ bounds = thumb_bounds context, args, extra_args
158
+ crop = args[:crop] || extra_args[:crop]
159
+ Jekyll::PathManager::join '', Shi::Jekyll::Images::File::create(page, shape, bounds, crop).url
160
+ end
161
+ fig_style += "shape-outside:url(#{shape_url});"
162
+ when String
163
+ fig_class += " __shape_#{shape}"
164
+ when true
165
+ fig_style += "shape-outside:url(#{src});"
166
+ end
167
+ result += "<figure class=\"#{fig_class}\" style=\"#{fig_style}\" markdown=\"0\">"
168
+ end
169
+ if link != false
170
+ if gen_big
171
+ result += "<a href=\"#{href}\" class=\"__image_link\">"
172
+ else
173
+ result += "<a href=\"#{href}\">"
174
+ end
175
+ end
176
+ # src = Jekyll::PathManager::join '', src
177
+ result += "<img src=\"#{src}\" #{attrs}>"
178
+ if link != false
179
+ result += '</a>'
180
+ end
181
+ if figure
182
+ if caption
183
+ result += "<figcaption markdown=\"span\">#{caption}</figcaption>"
184
+ end
185
+ result += '</figure>'
186
+ end
187
+
188
+ result
189
+ end
190
+ end
191
+
192
+ Liquid::Template.register_tag 'image', Shi::Jekyll::ImageTag
193
+
194
+ # Jekyll::Hooks::register :site, :post_write do |site|
195
+ # Shi::Jekyll::ImageTag::clean site
196
+ # end
197
+
198
+ # Jekyll::Hooks::register :pages, :pre_render do |*args|
199
+ # # puts "PAGE: #{args[0].class}: #{args[0].url}"
200
+ # # pp args[0].data
201
+ # if args[0].data['image']
202
+ # args[0].data['image'] = '/img/about/girl-1920x1080.webp'
203
+ # end
204
+ # # pp args[1]
205
+ # # puts 'PAGES:'
206
+ # # pp args.map { |i| i.class }
207
+ # end
208
+
209
+ # Jekyll::Hooks::register :documents, :pre_render do |*args|
210
+ # # puts "DOCUMENT: #{args[0].class}: #{args[0].url}"
211
+ # # pp args[0].data
212
+ # if args[0].data['image']
213
+ # args[0].data['image'] = '/img/about/girl-1920x1080.webp'
214
+ # end
215
+ # # pp args[1]
216
+ # end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'version'
4
+ require_relative 'config'
5
+ require_relative 'files'
6
+
7
+ module Shi::Jekyll::Images::SEO
8
+ class << self
9
+ include Shi::Jekyll::Images::Config
10
+
11
+ def file_by_path path
12
+ path_with_leading_slash = Jekyll::PathManager::join '', path
13
+ site.static_files.find { |f| f.relative_path == path || f.relative_path == path_with_leading_slash }
14
+ end
15
+
16
+ def process_page page
17
+ image = page.data['image']
18
+ if image
19
+ file = file_by_path image
20
+ if file
21
+ return nil if file.write?
22
+ bounds = get_value(page, 'seo_image_bounds') || '640x640'
23
+ crop = get_value(page, 'seo_image_crop') || '500:261+0+0'
24
+ result = Shi::Jekyll::Images::WebPFile::create page, file, bounds, crop
25
+ page.data['image'] = result.url
26
+ end
27
+ end
28
+ end
29
+
30
+ private :file_by_path
31
+ end
32
+ end
33
+
34
+ Jekyll::Hooks::register :pages, :pre_render do |page, *args|
35
+ Shi::Jekyll::Images::SEO::process_page page
36
+ end
37
+
38
+ Jekyll::Hooks::register :documents, :pre_render do |page, *args|
39
+ Shi::Jekyll::Images::SEO::process_page page
40
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pp' # TODO: remove for release
4
+
5
+ require 'fileutils'
6
+ require 'liquid'
7
+ require 'jekyll'
8
+ require 'shi/tools'
9
+ require 'shi/args'
10
+
11
+ module Shi
12
+ module Jekyll
13
+ module Images
14
+ VERSION = '0.1.0.9'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'images/version'
4
+ require_relative 'images/config'
5
+ require_relative 'images/files'
6
+ require_relative 'images/image'
7
+ require_relative 'images/figure'
8
+ require_relative 'images/seo'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'jekyll/images'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'shi/jekyll/images'
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shi-jekyll-images
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.9
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Shikhalev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-17 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: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: liquid
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '4.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: shi-tools
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.2.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.2.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: shi-args
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.3.4.2
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.3.4.2
75
+ description:
76
+ email:
77
+ - shikhalev@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".rufo"
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE.txt
86
+ - README.md
87
+ - lib/shi-jekyll-images.rb
88
+ - lib/shi/jekyll-images.rb
89
+ - lib/shi/jekyll/images.rb
90
+ - lib/shi/jekyll/images/config.rb
91
+ - lib/shi/jekyll/images/figure.rb
92
+ - lib/shi/jekyll/images/files.rb
93
+ - lib/shi/jekyll/images/image.rb
94
+ - lib/shi/jekyll/images/seo.rb
95
+ - lib/shi/jekyll/images/version.rb
96
+ homepage: https://github.com/shikhalev/shi-jekyll-images
97
+ licenses:
98
+ - MIT
99
+ metadata:
100
+ homepage_uri: https://github.com/shikhalev/shi-jekyll-images
101
+ source_code_uri: https://github.com/shikhalev/shi-jekyll-images
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: 2.7.7
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.4.3
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Jekyll plugin for image manipulation
121
+ test_files: []