jekyll-og-image 1.2.1 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a631d761ff53dd4360cc75a85dea82931684ec5feba0280c605cef0823b8a887
4
- data.tar.gz: bad0176739efbab1e7e9b1bc042e63c5b9be4673b1d47bb28ebcd305c015d100
3
+ metadata.gz: e246a8f729a0d3597ecdbb0b9b1b15083c6e23121d2f670c9b0911a16e0465eb
4
+ data.tar.gz: 203d4fa8e80623c91072f9eb5b02468085cca2a8cde171d325c1068eb7ccc2a9
5
5
  SHA512:
6
- metadata.gz: fb9ded5069c346291dbff870cb4925939e191c066e035d9c786886eee3cffc544f944e7bfd5f179125e7a02267c0ef7f45af061229ea817baba50fb8983a8251
7
- data.tar.gz: 9cc5b84d0b130db137d68cf6b513ff285648b90818a4e83d8b84c53b2832b0aaeeb53d750903c249619506c2dc2346276282733b18c53635195854d8a8ad25f4
6
+ metadata.gz: 1074de3a876df6c1856e4162aa260424b2972f9ae238bbc1060a36ce73f4cc82490e1ccf6d295e25f4a5e2719e54dae7ff199d779430856515e069a336a6909b
7
+ data.tar.gz: d9472379c623f304ab3a0ab95fd83a79a2ba9ccdc559319d747cec9d19432d7456e6a9bd036c13fab2f76fd8c12c2624ccefa5b647e99f6bbf18faa6127254fc
data/README.md CHANGED
@@ -26,11 +26,50 @@ plugins:
26
26
 
27
27
  Jekyll OG Image works together with [jekyll-seo-tag](https://github.com/jekyll/jekyll-seo-tag) plugin. It automatically generates open graph images for posts and inserts them into the posts metadata.
28
28
 
29
+ ## Configuration
30
+
31
+ The plugin can be configured in the `_config.yml` file or in the post's front matter.
32
+
33
+ The following configuration options are available:
34
+
35
+ * `output_dir` – The directory where the generated images will be saved. Default: `assets/images/og`
36
+
37
+ * `force` – If set to `true`, the plugin will generate an image for every post, even if the post already has an image. Default: `false`
38
+
39
+ * `verbose` – If set to `true`, the plugin will output additional information about the image generation process. Default: `false`
40
+
41
+ * `skip_drafts` – If set to `true`, the plugin will skip post drafts when generating images. Default: `true`
42
+
43
+ * `canvas` – The canvas configuration options:
44
+ * `background_color` – The background color of the canvas. Default: `#FFFFFF`
45
+ * `background_image` – The background image of the canvas. Default: `nil`
46
+
47
+ * `header` – The header configuration options:
48
+ * `font_family` – The font family of the header text. Default: `Helvetica, Bold`
49
+ * `color` – The color of the header text. Default: `#2f313d`
50
+
51
+ * `content` – The content configuration options:
52
+ * `font_family` – The font family of the content text. Default: `Helvetica, Regular`
53
+ * `color` – The color of the content text. Default: `#535358`
54
+
55
+ * `border_bottom` – The border bottom configuration options:
56
+ * `width` – The width of the border bottom. Default: `20`
57
+ * `fill` – The array of colors to fill the border bottom. Default: `["#000000"]`
58
+
59
+ * `domain` – The domain name to use in the image. Default: `nil`
60
+
61
+ * `image` – Path to the image to use as the logo. Default: `nil`
62
+
29
63
  ## Examples
30
64
 
65
+ Configuration can be defined on the site level or on the post level.
66
+
67
+ For a side wide level configuration, edit your `_config.yml`, for a post level configuration, edit the post's front matter.
68
+
31
69
  ### Single Color
32
70
 
33
71
  ```yaml
72
+ # _config.yml
34
73
  og_image:
35
74
  output_dir: "assets/images/og"
36
75
  domain: "igor.works"
@@ -45,6 +84,7 @@ og_image:
45
84
  ### Multiple Colors
46
85
 
47
86
  ```yaml
87
+ # _config.yml
48
88
  og_image:
49
89
  output_dir: "assets/images/og"
50
90
  image: "/assets/images/igor.jpeg"
@@ -64,6 +104,7 @@ og_image:
64
104
  ### Background Color and Text Color
65
105
 
66
106
  ```yaml
107
+ # _config.yml
67
108
  og_image:
68
109
  output_dir: "/assets/og"
69
110
  image: "/assets/images/igor.jpeg"
@@ -90,11 +131,10 @@ og_image:
90
131
  ### Background Image
91
132
 
92
133
  ```yaml
134
+ # _config.yml
93
135
  og_image:
94
136
  output_dir: "/assets/og"
95
137
  image: "/assets/images/igor.jpeg"
96
- canvas:
97
- background_image: "/assets/images/bc_3.jpg"
98
138
  header:
99
139
  font_family: "Roboto, Bold"
100
140
  color: "#333333"
@@ -103,6 +143,18 @@ og_image:
103
143
  color: "#333333"
104
144
  force: false
105
145
  domain: "igor.works"
146
+
147
+ # _posts/2024-02-15-traefik-tunning-for-rails-applications-part-1.md
148
+ ---
149
+ title: Traefik Tuning for Rails Applications (part 1)
150
+ layout: post
151
+ tags:
152
+ - Rails
153
+ - Traefik
154
+ - Kamal
155
+ og_image:
156
+ canvas:
157
+ background_image: "/assets/images/bc_3.jpg"
106
158
  ```
107
159
 
108
160
  ![Example 4](examples/4.png)
@@ -118,4 +170,4 @@ og_image:
118
170
 
119
171
  ## License
120
172
 
121
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
173
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,95 @@
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"].nil? ? false : @raw_config["force"]
58
+ end
59
+
60
+ def verbose?
61
+ @raw_config["verbose"].nil? ? false : @raw_config["verbose"]
62
+ end
63
+
64
+ def skip_drafts?
65
+ @raw_config["skip_drafts"].nil? ? true : @raw_config["skip_drafts"]
66
+ end
67
+
68
+ def canvas
69
+ @raw_config["canvas"] ? Canvas.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["canvas"])) : Canvas.new
70
+ end
71
+
72
+ def header
73
+ @raw_config["header"] ? Header.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["header"])) : Header.new
74
+ end
75
+
76
+ def content
77
+ @raw_config["content"] ? Content.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["content"])) : Content.new
78
+ end
79
+
80
+ def image
81
+ @raw_config["image"]
82
+ end
83
+
84
+ def domain
85
+ @raw_config["domain"]
86
+ end
87
+
88
+ def border_bottom
89
+ @raw_config["border_bottom"] ? Border.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["border_bottom"])) : nil
90
+ end
91
+
92
+ def margin_bottom
93
+ 80 + (border_bottom&.width || 0)
94
+ end
95
+ end
@@ -4,14 +4,13 @@ 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
 
14
11
  site.posts.docs.each do |post|
12
+ next if post.draft? && JekyllOgImage.config.skip_drafts?
13
+
15
14
  path = File.join(site.config["source"], base_path, "#{post.data['slug']}.png")
16
15
 
17
16
  if !File.exist?(path) || JekyllOgImage.config.force?
@@ -33,73 +32,88 @@ class JekyllOgImage::Generator < Jekyll::Generator
33
32
  private
34
33
 
35
34
  def generate_image_for_post(site, post, path)
36
- date = post.date.strftime("%B %d, %Y")
35
+ config = JekyllOgImage.config.merge!(post.data["og_image"])
36
+
37
+ canvas = generate_canvas(site, config)
38
+ canvas = add_border_bottom(canvas, config) if config.border_bottom
39
+ canvas = add_image(canvas, File.read(File.join(site.config["source"], config.image))) if config.image
40
+ canvas = add_header(canvas, post, config)
41
+ canvas = add_publish_date(canvas, post, config)
42
+ canvas = add_tags(canvas, post, config) if post.data["tags"].any?
43
+ canvas = add_domain(canvas, post, config) if config.domain
37
44
 
38
- background_image = if JekyllOgImage.config.canvas["background_image"]
39
- File.read(File.join(site.config["source"], JekyllOgImage.config.canvas["background_image"]))
45
+ canvas.save(path)
46
+ end
47
+
48
+ def generate_canvas(site, config)
49
+ background_image = if config.canvas.background_image
50
+ File.read(File.join(site.config["source"], config.canvas.background_image))
40
51
  end
41
52
 
42
- canvas = JekyllOgImage::Element::Canvas.new(1200, 600,
43
- background_color: JekyllOgImage.config.canvas["background_color"],
53
+ JekyllOgImage::Element::Canvas.new(1200, 600,
54
+ background_color: config.canvas.background_color,
44
55
  background_image: background_image
45
56
  )
57
+ end
46
58
 
47
- if JekyllOgImage.config.border_bottom
48
- canvas = canvas.border(JekyllOgImage.config.border_bottom["width"],
49
- position: :bottom,
50
- fill: JekyllOgImage.config.border_bottom["fill"]
51
- )
52
- end
59
+ def add_border_bottom(canvas, config)
60
+ canvas.border(config.border_bottom.width,
61
+ position: :bottom,
62
+ fill: config.border_bottom.fill
63
+ )
64
+ end
53
65
 
54
- if JekyllOgImage.config.image
55
- canvas = canvas.image(
56
- File.read(File.join(site.config["source"], JekyllOgImage.config.image)),
57
- gravity: :ne,
58
- width: 150,
59
- height: 150,
60
- radius: 50
61
- ) { |_canvas, _text| { x: 80, y: 100 } }
62
- end
66
+ def add_image(canvas, image)
67
+ canvas.image(image,
68
+ gravity: :ne,
69
+ width: 150,
70
+ height: 150,
71
+ radius: 50
72
+ ) { |_canvas, _text| { x: 80, y: 100 } }
73
+ end
63
74
 
64
- canvas = canvas.text(post.data["title"],
65
- width: JekyllOgImage.config.image ? 870 : 1040,
66
- color: JekyllOgImage.config.header["color"],
75
+ def add_header(canvas, post, config)
76
+ canvas.text(post.data["title"],
77
+ width: config.image ? 870 : 1040,
78
+ color: config.header.color,
67
79
  dpi: 400,
68
- font: JekyllOgImage.config.header["font_family"]
80
+ font: config.header.font_family
69
81
  ) { |_canvas, _text| { x: 80, y: 100 } }
82
+ end
70
83
 
71
- canvas = canvas.text(date,
84
+ def add_publish_date(canvas, post, config)
85
+ date = post.date.strftime("%B %d, %Y")
86
+
87
+ canvas.text(date,
72
88
  gravity: :sw,
73
- color: JekyllOgImage.config.content["color"],
89
+ color: config.content.color,
74
90
  dpi: 150,
75
- font: JekyllOgImage.config.content["font_family"]
76
- ) { |_canvas, _text| { x: 80, y: post.data["tags"].any? ? JekyllOgImage.config.margin_bottom + 50 : JekyllOgImage.config.margin_bottom } }
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
91
+ font: config.content.font_family
92
+ ) { |_canvas, _text| { x: 80, y: post.data["tags"].any? ? config.margin_bottom + 50 : config.margin_bottom } }
93
+ end
88
94
 
89
- if JekyllOgImage.config.domain
90
- canvas = canvas.text(JekyllOgImage.config.domain,
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
95
+ def add_tags(canvas, post, config)
96
+ tags = post.data["tags"].map { |tag| "##{tag}" }.join(" ")
102
97
 
103
- canvas.save(path)
98
+ canvas.text(tags,
99
+ gravity: :sw,
100
+ color: config.content.color,
101
+ dpi: 150,
102
+ font: config.content.font_family
103
+ ) { |_canvas, _text| { x: 80, y: config.margin_bottom } }
104
+ end
105
+
106
+ def add_domain(canvas, post, config)
107
+ canvas.text(config.domain,
108
+ gravity: :se,
109
+ color: config.content.color,
110
+ dpi: 150,
111
+ font: config.content.font_family
112
+ ) do |_canvas, _text|
113
+ {
114
+ x: 80,
115
+ y: post.data["tags"].any? ? config.margin_bottom + 50 : config.margin_bottom
116
+ }
117
+ end
104
118
  end
105
119
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllOgImage
4
- VERSION = "1.2.1"
4
+ VERSION = "1.4.1"
5
5
  end
@@ -11,18 +11,14 @@ loader.eager_load
11
11
 
12
12
  module JekyllOgImage
13
13
  def self.config
14
- @config ||= JekyllOgImage::Config.new
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::Config.new(site.config["og_image"])
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.2.1
4
+ version: 1.4.1
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-14 00:00:00.000000000 Z
11
+ date: 2024-06-24 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
@@ -94,7 +80,6 @@ extensions: []
94
80
  extra_rdoc_files: []
95
81
  files:
96
82
  - ".rspec"
97
- - ".rspec_status"
98
83
  - ".rubocop.yml"
99
84
  - CODE_OF_CONDUCT.md
100
85
  - LICENSE.txt
@@ -106,7 +91,7 @@ files:
106
91
  - examples/4.png
107
92
  - lib/jekyll-og-image.rb
108
93
  - lib/jekyll_og_image.rb
109
- - lib/jekyll_og_image/config.rb
94
+ - lib/jekyll_og_image/configuration.rb
110
95
  - lib/jekyll_og_image/element/base.rb
111
96
  - lib/jekyll_og_image/element/border.rb
112
97
  - lib/jekyll_og_image/element/canvas.rb
@@ -134,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
119
  - !ruby/object:Gem::Version
135
120
  version: '0'
136
121
  requirements: []
137
- rubygems_version: 3.5.3
122
+ rubygems_version: 3.5.11
138
123
  signing_key:
139
124
  specification_version: 4
140
125
  summary: Jekyll plugin to generate GitHub-style open graph images
data/.rspec_status DELETED
@@ -1,7 +0,0 @@
1
- example_id | status | run_time |
2
- ---------------------------------------------- | ------ | --------------- |
3
- ./spec/jekyll_og_image/config_spec.rb[1:1:1:1] | passed | 0.00046 seconds |
4
- ./spec/jekyll_og_image/config_spec.rb[1:1:2:1] | passed | 0.00012 seconds |
5
- ./spec/jekyll_og_image/version_spec.rb[1:1] | passed | 0.00037 seconds |
6
- ./spec/jekyll_og_image_spec.rb[1:1] | passed | 0.2806 seconds |
7
- ./spec/jekyll_og_image_spec.rb[1:2] | passed | 0.04456 seconds |
@@ -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