jekyll-og-image 1.2.1 → 1.3.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 +4 -4
- data/.rspec_status +27 -7
- data/lib/jekyll_og_image/configuration.rb +91 -0
- data/lib/jekyll_og_image/generator.rb +69 -57
- data/lib/jekyll_og_image/version.rb +1 -1
- data/lib/jekyll_og_image.rb +2 -6
- metadata +3 -17
- data/lib/jekyll_og_image/config.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d4faf0a2f12cf99798b8fb4fc56586ea659c37feceb3b34a7aac677fac0d43e
|
4
|
+
data.tar.gz: 6e7acd8ca461e1dc366255b3f01144fc3dca605eac70256ad1cc7fab135b3011
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aeea9d6fba76f7502a090f7d35dc2f062be6b1f7c5656f8d76719eeca715776fd818bd2f88faecd07b2d709bfbb3e0efbefeaac5c5c8f81f2b50af41bbc064a9
|
7
|
+
data.tar.gz: c602ea3d92aca6b20ef950c1300c4b28aecdc180a1076e12b1bcc9d7a5f7eb848511085c868b3af18385b432e6f1c7f44c1921ea85823400eb734ab1356d7d79
|
data/.rspec_status
CHANGED
@@ -1,7 +1,27 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/jekyll_og_image/
|
4
|
-
./spec/jekyll_og_image/
|
5
|
-
./spec/jekyll_og_image/
|
6
|
-
./spec/
|
7
|
-
./spec/
|
1
|
+
example_id | status | run_time |
|
2
|
+
------------------------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:1:1] | passed | 0.00097 seconds |
|
4
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:1:2:1] | passed | 0.00005 seconds |
|
5
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:2:1:1] | passed | 0.00005 seconds |
|
6
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:2:2:1] | passed | 0.00003 seconds |
|
7
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:3:1:1] | passed | 0.00026 seconds |
|
8
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:3:2:1] | passed | 0.00003 seconds |
|
9
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:4:1:1] | passed | 0.00003 seconds |
|
10
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:4:2:1] | passed | 0.00003 seconds |
|
11
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:5:1:1] | passed | 0.00039 seconds |
|
12
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:5:2:1] | passed | 0.00004 seconds |
|
13
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:6:1:1] | passed | 0.00004 seconds |
|
14
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:6:2:1] | passed | 0.00003 seconds |
|
15
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:7:1:1] | passed | 0.00004 seconds |
|
16
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:7:1:2:1] | passed | 0.00005 seconds |
|
17
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:8:1:1] | passed | 0.00004 seconds |
|
18
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:8:2:1] | passed | 0.00006 seconds |
|
19
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:9:1:1] | passed | 0.00004 seconds |
|
20
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:9:2:1] | passed | 0.00003 seconds |
|
21
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:10:1:1] | passed | 0.00003 seconds |
|
22
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:10:2:1] | passed | 0.00003 seconds |
|
23
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:11:1:1] | passed | 0.00003 seconds |
|
24
|
+
./spec/jekyll_og_image/configuration_spec.rb[1:11:2:1] | passed | 0.00003 seconds |
|
25
|
+
./spec/jekyll_og_image/version_spec.rb[1:1] | passed | 0.00003 seconds |
|
26
|
+
./spec/jekyll_og_image_spec.rb[1:1] | passed | 0.24499 seconds |
|
27
|
+
./spec/jekyll_og_image_spec.rb[1:2] | passed | 0.04171 seconds |
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# require "anyway_config"
|
4
|
+
|
5
|
+
class JekyllOgImage::Configuration
|
6
|
+
Canvas = Data.define(:background_color, :background_image) do
|
7
|
+
def initialize(background_color: "#FFFFFF", background_image: nil)
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Header = Data.define(:font_family, :color) do
|
13
|
+
def initialize(font_family: "Helvetica, Bold", color: "#2f313d")
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Content = Data.define(:font_family, :color) do
|
19
|
+
def initialize(font_family: "Helvetica, Regular", color: "#535358")
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Border = Data.define(:width, :fill) do
|
25
|
+
def initialize(width: 0, fill: nil)
|
26
|
+
fill.is_a?(Array) ? fill : [ fill ]
|
27
|
+
super(width: width, fill: fill)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(raw_config)
|
32
|
+
@raw_config = raw_config
|
33
|
+
end
|
34
|
+
|
35
|
+
def merge!(other)
|
36
|
+
config = Jekyll::Utils.deep_merge_hashes(
|
37
|
+
@raw_config,
|
38
|
+
other.to_h
|
39
|
+
)
|
40
|
+
|
41
|
+
self.class.new(config)
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_h
|
45
|
+
@raw_config
|
46
|
+
end
|
47
|
+
|
48
|
+
def ==(other)
|
49
|
+
to_h == other.to_h
|
50
|
+
end
|
51
|
+
|
52
|
+
def output_dir
|
53
|
+
@raw_config["output_dir"] || "assets/images/og"
|
54
|
+
end
|
55
|
+
|
56
|
+
def force?
|
57
|
+
@raw_config["force"] || false
|
58
|
+
end
|
59
|
+
|
60
|
+
def verbose?
|
61
|
+
@raw_config["verbose"] || false
|
62
|
+
end
|
63
|
+
|
64
|
+
def canvas
|
65
|
+
@raw_config["canvas"] ? Canvas.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["canvas"])) : Canvas.new
|
66
|
+
end
|
67
|
+
|
68
|
+
def header
|
69
|
+
@raw_config["header"] ? Header.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["header"])) : Header.new
|
70
|
+
end
|
71
|
+
|
72
|
+
def content
|
73
|
+
@raw_config["content"] ? Content.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["content"])) : Content.new
|
74
|
+
end
|
75
|
+
|
76
|
+
def image
|
77
|
+
@raw_config["image"]
|
78
|
+
end
|
79
|
+
|
80
|
+
def domain
|
81
|
+
@raw_config["domain"]
|
82
|
+
end
|
83
|
+
|
84
|
+
def border_bottom
|
85
|
+
@raw_config["border_bottom"] ? Border.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["border_bottom"])) : nil
|
86
|
+
end
|
87
|
+
|
88
|
+
def margin_bottom
|
89
|
+
80 + (border_bottom&.width || 0)
|
90
|
+
end
|
91
|
+
end
|
@@ -4,10 +4,7 @@ class JekyllOgImage::Generator < Jekyll::Generator
|
|
4
4
|
safe true
|
5
5
|
|
6
6
|
def generate(site)
|
7
|
-
base_path = File.join(
|
8
|
-
JekyllOgImage.config.output_dir,
|
9
|
-
"posts"
|
10
|
-
)
|
7
|
+
base_path = File.join(JekyllOgImage.config.output_dir, "posts")
|
11
8
|
|
12
9
|
FileUtils.mkdir_p File.join(site.config["source"], base_path)
|
13
10
|
|
@@ -33,73 +30,88 @@ class JekyllOgImage::Generator < Jekyll::Generator
|
|
33
30
|
private
|
34
31
|
|
35
32
|
def generate_image_for_post(site, post, path)
|
36
|
-
|
33
|
+
config = JekyllOgImage.config.merge!(post.data["og_image"])
|
37
34
|
|
38
|
-
|
39
|
-
|
35
|
+
canvas = generate_canvas(site, config)
|
36
|
+
canvas = add_border_bottom(canvas, config) if config.border_bottom
|
37
|
+
canvas = add_image(canvas, File.read(File.join(site.config["source"], config.image))) if config.image
|
38
|
+
canvas = add_header(canvas, post, config)
|
39
|
+
canvas = add_publish_date(canvas, post, config)
|
40
|
+
canvas = add_tags(canvas, post, config) if post.data["tags"].any?
|
41
|
+
canvas = add_domain(canvas, post, config) if config.domain
|
42
|
+
|
43
|
+
canvas.save(path)
|
44
|
+
end
|
45
|
+
|
46
|
+
def generate_canvas(site, config)
|
47
|
+
background_image = if config.canvas.background_image
|
48
|
+
File.read(File.join(site.config["source"], config.canvas.background_image))
|
40
49
|
end
|
41
50
|
|
42
|
-
|
43
|
-
background_color:
|
51
|
+
JekyllOgImage::Element::Canvas.new(1200, 600,
|
52
|
+
background_color: config.canvas.background_color,
|
44
53
|
background_image: background_image
|
45
54
|
)
|
55
|
+
end
|
46
56
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
57
|
+
def add_border_bottom(canvas, config)
|
58
|
+
canvas.border(config.border_bottom.width,
|
59
|
+
position: :bottom,
|
60
|
+
fill: config.border_bottom.fill
|
61
|
+
)
|
62
|
+
end
|
53
63
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
64
|
+
def add_image(canvas, image)
|
65
|
+
canvas.image(image,
|
66
|
+
gravity: :ne,
|
67
|
+
width: 150,
|
68
|
+
height: 150,
|
69
|
+
radius: 50
|
70
|
+
) { |_canvas, _text| { x: 80, y: 100 } }
|
71
|
+
end
|
63
72
|
|
64
|
-
|
65
|
-
|
66
|
-
|
73
|
+
def add_header(canvas, post, config)
|
74
|
+
canvas.text(post.data["title"],
|
75
|
+
width: config.image ? 870 : 1040,
|
76
|
+
color: config.header.color,
|
67
77
|
dpi: 400,
|
68
|
-
font:
|
78
|
+
font: config.header.font_family
|
69
79
|
) { |_canvas, _text| { x: 80, y: 100 } }
|
80
|
+
end
|
70
81
|
|
71
|
-
|
82
|
+
def add_publish_date(canvas, post, config)
|
83
|
+
date = post.date.strftime("%B %d, %Y")
|
84
|
+
|
85
|
+
canvas.text(date,
|
72
86
|
gravity: :sw,
|
73
|
-
color:
|
87
|
+
color: config.content.color,
|
74
88
|
dpi: 150,
|
75
|
-
font:
|
76
|
-
) { |_canvas, _text| { x: 80, y: post.data["tags"].any? ?
|
77
|
-
|
78
|
-
if post.data["tags"].any?
|
79
|
-
tags = post.data["tags"].map { |tag| "##{tag}" }.join(" ")
|
80
|
-
|
81
|
-
canvas = canvas.text(tags,
|
82
|
-
gravity: :sw,
|
83
|
-
color: JekyllOgImage.config.content["color"],
|
84
|
-
dpi: 150,
|
85
|
-
font: JekyllOgImage.config.content["font_family"]
|
86
|
-
) { |_canvas, _text| { x: 80, y: JekyllOgImage.config.margin_bottom } }
|
87
|
-
end
|
89
|
+
font: config.content.font_family
|
90
|
+
) { |_canvas, _text| { x: 80, y: post.data["tags"].any? ? config.margin_bottom + 50 : config.margin_bottom } }
|
91
|
+
end
|
88
92
|
|
89
|
-
|
90
|
-
|
91
|
-
gravity: :se,
|
92
|
-
color: JekyllOgImage.config.content["color"],
|
93
|
-
dpi: 150,
|
94
|
-
font: JekyllOgImage.config.content["font_family"]
|
95
|
-
) do |_canvas, _text|
|
96
|
-
{
|
97
|
-
x: 80,
|
98
|
-
y: post.data["tags"].any? ? JekyllOgImage.config.margin_bottom + 50 : JekyllOgImage.config.margin_bottom
|
99
|
-
}
|
100
|
-
end
|
101
|
-
end
|
93
|
+
def add_tags(canvas, post, config)
|
94
|
+
tags = post.data["tags"].map { |tag| "##{tag}" }.join(" ")
|
102
95
|
|
103
|
-
canvas.
|
96
|
+
canvas.text(tags,
|
97
|
+
gravity: :sw,
|
98
|
+
color: config.content.color,
|
99
|
+
dpi: 150,
|
100
|
+
font: config.content.font_family
|
101
|
+
) { |_canvas, _text| { x: 80, y: config.margin_bottom } }
|
102
|
+
end
|
103
|
+
|
104
|
+
def add_domain(canvas, post, config)
|
105
|
+
canvas.text(config.domain,
|
106
|
+
gravity: :se,
|
107
|
+
color: config.content.color,
|
108
|
+
dpi: 150,
|
109
|
+
font: config.content.font_family
|
110
|
+
) do |_canvas, _text|
|
111
|
+
{
|
112
|
+
x: 80,
|
113
|
+
y: post.data["tags"].any? ? config.margin_bottom + 50 : config.margin_bottom
|
114
|
+
}
|
115
|
+
end
|
104
116
|
end
|
105
117
|
end
|
data/lib/jekyll_og_image.rb
CHANGED
@@ -11,18 +11,14 @@ loader.eager_load
|
|
11
11
|
|
12
12
|
module JekyllOgImage
|
13
13
|
def self.config
|
14
|
-
@config ||= JekyllOgImage::
|
14
|
+
@config ||= JekyllOgImage::Configuration.new({})
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.config=(config)
|
18
18
|
@config = config
|
19
19
|
end
|
20
|
-
|
21
|
-
def self.configure
|
22
|
-
yield config
|
23
|
-
end
|
24
20
|
end
|
25
21
|
|
26
22
|
Jekyll::Hooks.register(:site, :after_init) do |site|
|
27
|
-
JekyllOgImage.config = JekyllOgImage::
|
23
|
+
JekyllOgImage.config = JekyllOgImage::Configuration.new(site.config["og_image"] || {})
|
28
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-og-image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Alexandrov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll-seo-tag
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.6'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: anyway_config
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '2.6'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '2.6'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: ruby-vips
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,7 +92,7 @@ files:
|
|
106
92
|
- examples/4.png
|
107
93
|
- lib/jekyll-og-image.rb
|
108
94
|
- lib/jekyll_og_image.rb
|
109
|
-
- lib/jekyll_og_image/
|
95
|
+
- lib/jekyll_og_image/configuration.rb
|
110
96
|
- lib/jekyll_og_image/element/base.rb
|
111
97
|
- lib/jekyll_og_image/element/border.rb
|
112
98
|
- lib/jekyll_og_image/element/canvas.rb
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "anyway_config"
|
4
|
-
|
5
|
-
class JekyllOgImage::Config < Anyway::Config
|
6
|
-
attr_config output_dir: "assets/images/og"
|
7
|
-
attr_config force: false
|
8
|
-
attr_config verbose: false
|
9
|
-
attr_config canvas: {
|
10
|
-
background_color: "#FFFFFF",
|
11
|
-
background_image: nil
|
12
|
-
}
|
13
|
-
attr_config header: {
|
14
|
-
font_family: "Helvetica, Bold",
|
15
|
-
color: "#2f313d"
|
16
|
-
}
|
17
|
-
attr_config content: {
|
18
|
-
font_family: "Helvetica, Regular",
|
19
|
-
color: "#535358"
|
20
|
-
}
|
21
|
-
attr_config :image
|
22
|
-
attr_config :domain
|
23
|
-
attr_config :border_bottom
|
24
|
-
|
25
|
-
coerce_types canvas: {
|
26
|
-
background_color: { type: :string },
|
27
|
-
background_image: { type: :string }
|
28
|
-
}
|
29
|
-
|
30
|
-
coerce_types header: {
|
31
|
-
font_family: { type: :string },
|
32
|
-
color: { type: :string }
|
33
|
-
}
|
34
|
-
|
35
|
-
coerce_types content: {
|
36
|
-
font_family: { type: :string },
|
37
|
-
color: { type: :string }
|
38
|
-
}
|
39
|
-
|
40
|
-
coerce_types image: { type: :string }
|
41
|
-
|
42
|
-
coerce_types border_bottom: {
|
43
|
-
width: { type: :integer },
|
44
|
-
fill: { type: :string, array: true }
|
45
|
-
}
|
46
|
-
|
47
|
-
def margin_bottom
|
48
|
-
80 + (border_bottom&.fetch("width", 0) || 0)
|
49
|
-
end
|
50
|
-
end
|