jekyll_picture_tag 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll_picture_tag/defaults/global.yml +1 -0
- data/lib/jekyll_picture_tag/generated_image.rb +4 -6
- data/lib/jekyll_picture_tag/instructions/configuration.rb +20 -8
- data/lib/jekyll_picture_tag/instructions/preset.rb +2 -2
- data/lib/jekyll_picture_tag/source_image.rb +37 -9
- data/lib/jekyll_picture_tag/version.rb +1 -1
- data/readme.md +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 938a170ac5a3ee774c6d8b95ac2a34e20a1edad04937acf49c7e7bdd081f3b81
|
4
|
+
data.tar.gz: 1648ce3bdf88de7acf55c17d675bfab1ce641cf00a1138b3cf32abafc4824e96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce995d57c31dd2beb97c13288a05cca94eaa2ce242e30bcfaf643154dbeec099ce5fa14566b54bd8fc14b21cf8f9da86028fa583f71ad965f368b9db46930ecf
|
7
|
+
data.tar.gz: 105c64ae46f7a5a92c7a198c3ae48e6d49d16493e619107afd0d7c473f577bde43c3baebdfda0692e927fe915f1743dd86ffe8aad7b09c0b48b6b50136625844
|
@@ -4,12 +4,14 @@ class GeneratedImage
|
|
4
4
|
require 'mini_magick'
|
5
5
|
require 'fastimage'
|
6
6
|
|
7
|
+
attr_reader :width
|
8
|
+
|
7
9
|
def initialize(source_file:, width:, format:)
|
8
10
|
@source = source_file
|
9
11
|
@width = width
|
10
12
|
@format = format
|
11
13
|
|
12
|
-
generate_image unless File.exist?
|
14
|
+
generate_image unless File.exist?(absolute_filename) || @source.missing
|
13
15
|
end
|
14
16
|
|
15
17
|
def name
|
@@ -23,10 +25,6 @@ class GeneratedImage
|
|
23
25
|
@absolute_filename ||= File.join(PictureTag.config.dest_dir, name)
|
24
26
|
end
|
25
27
|
|
26
|
-
def width
|
27
|
-
@width
|
28
|
-
end
|
29
|
-
|
30
28
|
private
|
31
29
|
|
32
30
|
def generate_image
|
@@ -45,7 +43,7 @@ class GeneratedImage
|
|
45
43
|
|
46
44
|
image.write absolute_filename
|
47
45
|
|
48
|
-
FileUtils.chmod(
|
46
|
+
FileUtils.chmod(0o644, absolute_filename)
|
49
47
|
end
|
50
48
|
|
51
49
|
# Make sure destination directory exists
|
@@ -14,7 +14,7 @@ module PictureTag
|
|
14
14
|
# Digs into jekyll context, returns current environment
|
15
15
|
def jekyll_env
|
16
16
|
# It would be really great if the jekyll devs actually documented
|
17
|
-
# the context object.
|
17
|
+
# the context object.
|
18
18
|
PictureTag.context.environments.first['jekyll']['environment']
|
19
19
|
end
|
20
20
|
|
@@ -51,6 +51,19 @@ module PictureTag
|
|
51
51
|
Utils.markdown_page? && self['picture']['nomarkdown']
|
52
52
|
end
|
53
53
|
|
54
|
+
def continue_on_missing?
|
55
|
+
setting = @content['picture']['ignore_missing_images']
|
56
|
+
|
57
|
+
# Config setting can be a string, an array, or a boolean
|
58
|
+
if setting.is_a? Array
|
59
|
+
setting.include? jekyll_env
|
60
|
+
elsif setting.is_a? String
|
61
|
+
setting == jekyll_env
|
62
|
+
else
|
63
|
+
setting
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
54
67
|
private
|
55
68
|
|
56
69
|
def build_config
|
@@ -84,14 +97,14 @@ module PictureTag
|
|
84
97
|
# Juuust complicated enough to extract to its own function.
|
85
98
|
def cdn?
|
86
99
|
self['picture']['cdn_url'] &&
|
87
|
-
self['picture']['cdn_environments'].include?(
|
100
|
+
self['picture']['cdn_environments'].include?(jekyll_env)
|
88
101
|
end
|
89
102
|
|
90
103
|
# https://example.com/my-base-path/assets/generated-images/image.jpg
|
91
104
|
# ^^^^^^^^^^^^^^^^^^^^
|
92
105
|
# | domain | baseurl | j-p-t output dir | filename
|
93
106
|
def domain
|
94
|
-
if cdn?
|
107
|
+
if cdn?
|
95
108
|
self['picture']['cdn_url']
|
96
109
|
elsif self['picture']['relative_url']
|
97
110
|
''
|
@@ -106,12 +119,11 @@ module PictureTag
|
|
106
119
|
def url_prefix
|
107
120
|
# We use file.join because the ruby url methods don't like relative
|
108
121
|
# urls.
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
122
|
+
File.join(
|
123
|
+
domain,
|
124
|
+
self['baseurl']
|
125
|
+
)
|
113
126
|
end
|
114
|
-
|
115
127
|
end
|
116
128
|
end
|
117
129
|
end
|
@@ -60,8 +60,8 @@ module PictureTag
|
|
60
60
|
|
61
61
|
def no_preset
|
62
62
|
Utils.warning(
|
63
|
-
" Preset \"#{@name}\" not found in
|
64
|
-
'markup_presets key. Using default values.'
|
63
|
+
" Preset \"#{@name}\" not found in #{PictureTag.config['data_dir']}/"\
|
64
|
+
+ 'picture.yml under markup_presets key. Using default values.'
|
65
65
|
)
|
66
66
|
|
67
67
|
{}
|
@@ -3,7 +3,7 @@ module PictureTag
|
|
3
3
|
# advantage by storing expensive file reads and writes in instance variables,
|
4
4
|
# to be reused by many different source images.
|
5
5
|
class SourceImage
|
6
|
-
attr_reader :name, :shortname
|
6
|
+
attr_reader :name, :shortname, :missing
|
7
7
|
|
8
8
|
def initialize(relative_filename)
|
9
9
|
@shortname = relative_filename
|
@@ -18,12 +18,12 @@ module PictureTag
|
|
18
18
|
size[:width]
|
19
19
|
end
|
20
20
|
|
21
|
-
def aspect_ratio
|
22
|
-
@aspect_ratio ||= size[:width].to_f / size[:height].to_f
|
23
|
-
end
|
24
|
-
|
25
21
|
def digest
|
26
|
-
@digest ||=
|
22
|
+
@digest ||= if @missing
|
23
|
+
'x' * 6
|
24
|
+
else
|
25
|
+
Digest::MD5.hexdigest(File.read(@name))[0..5]
|
26
|
+
end
|
27
27
|
end
|
28
28
|
|
29
29
|
# Includes path relative to default sorce folder, and the original filename.
|
@@ -40,7 +40,12 @@ module PictureTag
|
|
40
40
|
private
|
41
41
|
|
42
42
|
def build_size
|
43
|
-
|
43
|
+
if @missing
|
44
|
+
width = 999_999
|
45
|
+
height = 999_999
|
46
|
+
else
|
47
|
+
width, height = FastImage.size(@name)
|
48
|
+
end
|
44
49
|
|
45
50
|
{
|
46
51
|
width: width,
|
@@ -52,11 +57,34 @@ module PictureTag
|
|
52
57
|
def grab_file(source_file)
|
53
58
|
source_name = File.join(PictureTag.config.source_dir, source_file)
|
54
59
|
|
55
|
-
|
56
|
-
|
60
|
+
if File.exist? source_name
|
61
|
+
@missing = false
|
62
|
+
|
63
|
+
elsif PictureTag.config.continue_on_missing?
|
64
|
+
@missing = true
|
65
|
+
Utils.warning missing_image_warning(source_name)
|
66
|
+
|
67
|
+
else
|
68
|
+
raise missing_image_error(source_name)
|
57
69
|
end
|
58
70
|
|
59
71
|
source_name
|
60
72
|
end
|
73
|
+
|
74
|
+
def missing_image_warning(source_name)
|
75
|
+
<<~HEREDOC
|
76
|
+
Could not find #{source_name}. Your site will have broken images in it.
|
77
|
+
Continuing.
|
78
|
+
HEREDOC
|
79
|
+
end
|
80
|
+
|
81
|
+
def missing_image_error(source_name)
|
82
|
+
<<~HEREDOC
|
83
|
+
Jekyll Picture Tag could not find #{source_name}. You can force the
|
84
|
+
build to continue anyway by setting "picture: ignore_missing_images:
|
85
|
+
true" in "_config.yml". This setting can also accept a jekyll build
|
86
|
+
environment, or an array of environments.
|
87
|
+
HEREDOC
|
88
|
+
end
|
61
89
|
end
|
62
90
|
end
|
data/readme.md
CHANGED
@@ -178,6 +178,9 @@ modifications and I'll take care of it.
|
|
178
178
|
|
179
179
|
# Release History
|
180
180
|
|
181
|
+
* 1.6.0 Jul 2, 2019:
|
182
|
+
* Missing Preset warning respects `data_dir` setting
|
183
|
+
* Add `continue_on_missing` option
|
181
184
|
* 1.5.0 Jun 26, 2019:
|
182
185
|
* better `{::nomarkdown}` necessity detection
|
183
186
|
* allow user to override `{::nomarkdown}` autodetection
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_picture_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Wierzbowski
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-07-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|